Re: Question on Threads



On 2007-11-22 23:15:42 -0800, Ravi <v.r.sankar@xxxxxxxxx> said:

Hi,

Just wanted to clarify. Please correct me if I went wrong anywhere.

Threads seize their current execution in two ways

I think you meant "cease", as in to stop or desist, not "seize", to take by force...

1) When they encounter a synchronized block and the object lock is not
available. They would be put in a Object Lock Monitor Queue. This
queue is managed by JVM. That is object lock acquiring and releasing
is automatically taken care by JVM on behalf of the thread
(programmer).
2) When the thread calls wait() from a synchronized block. It is then
put in Object's wait queue for which it acquired the lock and the lock
is released. Notify() by another thread brings it backs to life and
the fight for Object lock begins when it becomes the current execution
thread. The wait() and notify() have to programmed explicitly.

Threads are also likely to be suspended any time they call a blocking system service: even reading from a file, on most OSes, makes a thread eligible for suspension so that the OS can schedule the disk read while allowing other threads to use the CPU while the IO-bound thread waits for its data.

There are also explicit locks that may or may not be implemented using synchronization and wait()/notify() in the java.util.concurrent package. On some platforms, there are native equivalents of the same locking tools that are much faster than a pure-Java implementation would be. Attempting to acquire a lock that isn't available will also block the calling thread.

.



Relevant Pages

  • Re: synchronizations of threads
    ... To answer your immediate question, it's not the lock using workLock that's superfluous, it's the lock using workQueue. ... As has been discussed elsewhere, including in Jon Skeet's web article on threading, using a privately allocated instance of Object for a lock is preferable to using the object that actually needs the synchronized access, because doing so ensures that only that particular code is locking on that particular object. ... I am surprised to see the non-generic Queue class being used, but more significantly the use of the "stop" variable to signal a shutdown rather than just communicating through the queue, which leads to the two-second timeout, another questionable design choice, and the fact that the workLock lock is held during the entire execution of the worker delegate, these are all bad problems IMHO. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Question on Threads
    ... Threads seize their current execution in two ways ... They would be put in a Object Lock Monitor Queue. ... eligible for suspension so that the OS can schedule the disk read while ...
    (comp.lang.java.programmer)
  • Re: This works, but I dont know why :)
    ... there are overlays still on disk the exe needs ... My Clipper exes, all overlaid, are always open ... Have an active lock? ... operation the first step in execution. ...
    (comp.lang.clipper)
  • Re: Question on Threads
    ... Threads seize their current execution in two ways ... They would be put in a Object Lock Monitor Queue. ... There are also explicit locks that may or may not be implemented using synchronization and wait/notifyin the java.util.concurrent package. ... This book if full of a complete and intuitive explanation of all of the current Java Concurrency features, ...
    (comp.lang.java.programmer)
  • Re: Question on Locks
    ... the execution plan will be a plain table scan. ... In a production database, columns that are searched on a regular basis ... And if a rare search ... size table than by some milliseconds of waiting for a lock to be released. ...
    (microsoft.public.sqlserver.programming)

Loading