• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Thread

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this code:
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maria Garcia:
try this code:


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 [4] 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
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody throw some light on this :roll:
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tyler,
That helps
Sri
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic