• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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?
 
Sheriff
Posts: 23711
50
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.
 
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
 
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.
 
author
Sheriff
Posts: 23588
138
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()?
 
Ranch Hand
Posts: 3091
15
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!