*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
Guyz , consider a scenario where there is one source and multiple threads (lets say 4 threads) are accessing it. Why it happen that even we write thread1.start() first and then start() of second thread and then third one and then start of fourth thread, but we can never give surity that thread1 will access the source first.
I hope scenario is clear.
waiting for reply
regards
khurram fakhar
sushant
Greenhorn

Joined: Apr 21, 2000
Posts: 26
hi Khurram Fakhar,
The reason that u cannot expect which thread will execute and when is that, no matter in what order u start the threads, it is upto the jvm to decide which thread gets to run.
So the bottomline is that u cannot predict which thread gets to execute from a pool of threads.
hope that answers ur question.
Sushant.
Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
Thanx sushant , but i know this thing already,
problem is how JVM decides i mean upon which algorithm that which thread should execute first . SOME Random strategy or what.
that thing is confusing me nothing else
Regards
Khurram Fakhar
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
Hie,
Actually it is not entirely, if at all, the responsibility of the JVM to decide which threads execute first, and in what order.It is up to the actual native thread implementation.Java's thread scheduling policy ensures that all threads get at least the same chance to execute,regardless of priorities,but recall that Java threads are only an abstraction of real native threads of execution, hence it is up to the implementation of these that thread behavior can be guaranteed.You can however, implement your own thread scheduler and make thread behaviour deterministic at application level.
Regards,
Herbert
 
jQuery in Action, 2nd edition
 
subject: Threads
 
Similar Threads
Playing 1 sound after another
Synchronized ?
DB2 CallableStatement [max. number of statement exceeded issue]
Thread- Synchronized question
about threads, using locks of the objects in synchronized blocks