• Post Reply Bookmark Topic Watch Topic
  • New Topic

When a thread is in sleep 1000ms - Thread.sleep(1000), does the thread unlock the resource?

 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a thread is in sleep 1000ms (Thread.sleep(1000)), does the thread unlock the resource during the 1000ms so other threads can access the resource?
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What resource would that be? Perhaps a short example would explain the question?
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The resource can be a section of synchronized code or a JDBC Connection the thread uses to access DB.
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Brown wrote:When a thread is in sleep 1000ms (Thread.sleep(1000)), does the thread unlock the resource during the 1000ms so other threads can access the resource?

I don't think thread.sleep releases the lock, it's wait()

please confirm

thanks & regards
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhakar Sharma is correct. sleep() does not release locks.
 
Henry Wong
author
Sheriff
Posts: 22516
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward Harned wrote:Sudhakar Sharma is correct. sleep() does not release locks.


The Thread.sleep() method doesn't release any JDBC connections either.

Henry
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So wait() and waitFor() will cause the thread to release the resource, including the JDBC Connection?

What about join() and yield()?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Brown wrote:So wait() and waitFor() will cause the thread to release the resource, including the JDBC Connection?

No, waitFor() doesn't release anything. And wait() only releases the lock on the object used to call wait(), not any other resource.

Matt Brown wrote:What about join() and yield()?

These don't release anything.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!