• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization and access  RSS feed

 
Fitz Herbert
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do Synchronized methods need to be private? And when a piece of code is synchronized, is this just within the package or through out?
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, typically sychronized methods are not private. In most cases, a private synchronized method wouldn't be useful. A method is synchronized for an object (or the whole class if you use static synchronized). Only one thread at a time in the whole JVM can access synchronized sections of the object (or class). Packages have nothing to do with it.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at Suns Thread Tutorial...
 
Fitz Herbert
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou for the response.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!