File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Synchronization and access Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Synchronization and access" Watch "Synchronization and access" New topic
Author

Synchronization and access

Fitz Herbert
Greenhorn

Joined: Mar 22, 2003
Posts: 21
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
Bartender

Joined: Oct 01, 2001
Posts: 1855

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

Joined: Jul 11, 2001
Posts: 14112
Take a look at Suns Thread Tutorial...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Fitz Herbert
Greenhorn

Joined: Mar 22, 2003
Posts: 21
Thankyou for the response.
 
 
subject: Synchronization and access
 
Threads others viewed
Why am I getting NullPointerException?
Vector V/s ArrayList
synchronized context
THREAD
Blocking I/O using Iterator()
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com