we all know when we use synchronized we prevent the second thread enter until the first one executed but her if you use for loop then we can see the output move from one to anther and if you remove the for loop you can see the true output 0 thread first then -1 thread later any explanation please Best wishes
The two threads are not properly synchronized. When synchronized is used on an instance method, the monitor of the instance on which the method was called is used. Thus in the example there are two monitors: one of the object pointed to by b1, and the other by b2. In order to synchronize them properly use a common lock.
Maria, I want to know whether it is legal to override the start() method of the thread class because I recall reading a post by Jim Yingst see post named Thread 01/21 08:40pm  at Java Programmer Certification forum. I am quoting the answer of jim
Because you're not supposed to override the start() method. That's the method that actually knows how to start a new, separate thread. If you do override it, you should call super.start() to invoke the original funcionality, rather than calling run().
Can somebody explain me why can/cant we overrride the start method ? Thanks in advance Sri
I could be wrong, but I don't think you should override the start method unless you really know what you're doing... The start method creates a new call stack for the thread, puts it into the runnable state, sets the priority, and, I'm speculating, maps the thread to a native Operating System thread of execution in most cases. That's an awful lot of stuff to be doing and probably just scratches the surface, so unless you properly implement it all you shouldn't be overriding the start method. [ February 11, 2003: Message edited by: Tyler Durden ]
when you override the start() method in Thread's subclass,without calling the super.start(),the run() method doesn't perform as the starting point of a thread's executing,am I right? [ February 12, 2003: Message edited by: Mellihoney Michael ]
a beginner in java
There is no "i" in denial. Tiny ad:
a bit of art, as a gift, the permaculture playing cards