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 & Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread & Synchronization" Watch "Thread & Synchronization" New topic
Author

Thread & Synchronization

Umashanthi Pavalanathan
Greenhorn

Joined: Feb 15, 2007
Posts: 18
Please give me the possible answers and explanation for the following questions. Is there any different way to compile and run Thread Programs?in these in the normal way but no output.
Thanks in Advance,
Ushan.
que1)
------
class A extends Thread
{
private static String []A={"X","Y","Z"};
public void run()
{
System.out.println(A[0]+A[1]+A[2]);
}
public static void main(String aa[])
{
{
Thread t=new Thread();
System.out.println("AAAA");
t.start();
A[0]="A";A[1]="B";A[2]="C";
}
}

que2
-----

class A extends Thread
{
private static String []A={"X","Y","Z"};
public synchronized void run()
{
System.out.println(A[0]+A[1]+A[2]);
}
public static void main(String aa[])
{
synchronized(A) {
Thread t=new Thread();
System.out.println("AAAA");
t.start();
A[0]="A";A[1]="B";A[2]="C";
}

}
}
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi,

clarification needed Thread t= new Thread() or Thread t = new A();


Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Umashanthi Pavalanathan
Greenhorn

Joined: Feb 15, 2007
Posts: 18
It is Thread t=new Thread();
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Umashanthi,

I recommend to see Thread API, and see How to create a Thread which can execute your run().

All the best.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Thread & Synchronization
 
Similar Threads
Threads
Dan's thread
Thread Question
Threads - synchronized methods
Thread Qn from Dan mock exam site