File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread Watch "thread New topic
Author

thread's

nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
class callme
{
synchronized void call(String msg)
{
System.out.println("["+msg);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("interrupted");
}
System.out.println("]");
}
}
class caller implements Runnable
{
String msg;
callme target;
Thread t;
public caller(callme targ,String s)
{
target=targ;
msg=s;
t=new Thread(this);
t.start();
}
public void run()
{

target.call(msg);

}
}
class synch
{
public static void main(String[]args)
{

callme target=new callme();
caller ob1=new caller(target,"hello");
caller ob2=new caller(target,"synchronized");
caller ob3=new caller(target,"world");

try
{

ob1.t.join();
ob2.t.join();
ob3.t.join();

}
catch(InterruptedException e)
{
System.out.println("interrupted");
}
}
}
the output is:
[hello
]
[synchronize
]
[world
]

can it be altered by scheduler like this or in some other sequence?.Please help me.
for eg
[synchronize
]
[world
]
[hello
]
sir,In the above given code,can we predict the output with 100 percent surety?In this programme output is coming same each and every time but tell me whether it's upto the scheduler to start the thread of it's choice or not, looking at the fact that all the three thread's have same priority.please throw some fire on it.
Please tell me the url of sun tutorial so that i can clear my concept's regarding THREAD'S, having sleepless night's because of THREADING..

Pratap Reddy
Ranch Hand

Joined: Jan 05, 2001
Posts: 36
Hi Nitin,
Here is the url http://java.sun.com/docs/books/tutorial/essential/threads/index.html for Sun threads concepts. You are right there is no way to perdict 100% correct answer. It all depends on OS system.
It might be peemetive or timeslice.
Pratap
Sun Certified programmer for Java 1.2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: thread's