Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Run Method

Thread view: 
ndxp@hotmail.com - 13 Dec 2005 14:27 GMT
I'm kind of confused here -

class A extends Thread {

public void run() {

synchronized (...) {

}
}

}

what may be the use of having a synchronized block in a thread's run
method ? I was under
the impression, that only one thread will access the run method i,e the
current running thread.

-t
BartCr - 13 Dec 2005 14:49 GMT
You can have multiple A's all running at the same time, synchronizing
on a shared object. That way only one of all A threads will execute the
code in the block at the same time.

A use for this might be where multiple threads append to the same file
from that run method. This way it is assured that the written data will
not end mixed up.

Bart


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.