The idea is simple. By introducing named "breakpoints" in code run by threads, the test management code can control the execution of a thread by telling it to go to a certain breakpoint. Breakpoints are added to normal code using statements like:
assert TestableThread.breakpoint("breakA");
By using an assert, the breakpoint code will not incur any performance penalty when the software is run in production (the default way to run Java software is without -ea, that is, without enabling assertions).
Given defined breakpoints, test code can let threads execute till they reach a given named breakpoint, for example, the code:
t1.goTo("breakA");
will enable the t1 thread to run until it reaches breakpoint "breakA". When the breakpoint is reached, the t1 thread will stop executing until it gets another goTo() request.
The implementation below is only 50 LOCs or something, but still have been shown to be useful. There are, of course, lots of improvements / additions to be made including conditional breakpoints.
Code:
public class TestableThread extends Thread {
private final Object sync = new Object();
private volatile String breakName;
public TestableThread(Runnable r) {
super(r);
}
/**
* Run thread until it hits the named breakpoint or exits.
*/
public void goTo(String breakName) {
synchronized (sync) {
this.breakName = breakName;
sync.notifyAll();
}
if (getState() == Thread.State.NEW) {
start();
}
}
/**
* Run thread, not stopping at any break points.
*/
public void go() {
goTo(null);
}
public static boolean breakpoint(String breakName) {
if (breakName == null) {
throw new IllegalArgumentException("breakName == null not allowed");
}
Thread thread = Thread.currentThread();
if (thread instanceof TestableThread) {
TestableThread tt = (TestableThread) thread;
synchronized (tt.sync) {
while (tt.breakName != null && tt.breakName.equals(breakName)) {
try {
tt.sync.wait();
} catch (InterruptedException e) {
throw new Error("not expected: " + e);
}
}
}
}
return true;
}
}
The programming was very easily understand and more important coding are provided on this post and this is very valuable in my studies,all coding easily understand and develop more skills,thanks for sharing this post.
ReplyDeletehadoop
ReplyDeleteReally very nice blog information for this one and more technical skills are improve,i like that kind of post.
SAP training in Chennai
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleteSAP training in Chennai
Thanks for this blog. All screenshots can explain the full blogs easily. This is very easy to understand. Using this screen shots know the details becomes easy.
ReplyDeletePPC Services Chennai
This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.
ReplyDeleteYour final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.
Informatica Training in Chennai
thanks for giving that type of information. ielts coaching in gurgaon
ReplyDeleteThis is a fabulous article, please try to give more useful information.
ReplyDeleteimportance of cloud computing
why cloud computing is important
advantages of machine learning
advantages of devops
difference between asp and php
javascript interview questions advanced
This article will outline all the different strategies you should be aware of when it comes to soccer.
ReplyDeleteBest IAS Coaching In India
Great Read! thanks for the information shared here as it helped our team to solve some roadblocks for our tasks! Carlo Picasso Decorators
ReplyDeleteI really like this article and how you make it interesting.Freestanding Gas BBQs
ReplyDelete"I read your blogs and really thankful for sharing it :)Wood Fired and Charcoal BBQs
ReplyDelete"
I really like this article and how you make it interesting!veterinary prescriber
ReplyDeleteI really like this article and how you make it interesting. - d and d merchandise
ReplyDeleteThank you for sharing the valuable insights on your blog. Posts that discuss topics such as databases, NoSQL systems, and practical cryptography are very helpful for developers and technology enthusiasts who want to deepen their understanding of modern IT concepts. Articles like these make complex technical ideas easier to understand and encourage readers to explore innovative approaches in software development and data management.
ReplyDeleteIn today’s rapidly evolving technology landscape, continuous learning and practical skill development are essential for building a strong career in IT. Training platforms like Login360 help learners gain industry-relevant knowledge through hands-on projects and structured programs. Those interested in developing strong technical careers can explore programs such as
Data Science and
Full Stack Development
Really enjoyed browsing your blog — such a nice mix of interesting posts and clear writing! Thanks for putting this content out there. For anyone looking to expand their skills, check out UI/UX Course in Kochi by Login360 and Digital Marketing Course by Login360
ReplyDelete— both are great resources worth exploring.
Great post! I really enjoy how your writing combines thoughtful ideas with clear explanations it’s refreshing and insightful. For readers looking to grow their creative and professional skill set alongside engaging content like this, you might check out a Digital Marketing Training Institute in Coimbatore or a UI UX Design Course in Coimbatore. Keep up the excellent work!
ReplyDeleteReading about open-source work and development practices always helps learners improve their understanding of software development. For beginners exploring programming, resources like Java Course and Python Course can also help build strong coding fundamentals.
ReplyDelete