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 / February 2007

Tip: Looking for answers? Try searching our database.

threads scheduling

Thread view: 
divyatiwari123@gmail.com - 23 Feb 2007 12:34 GMT
Can we not use the getName() method  to schedule the threads??

Following code gives the output without any delay..............

import java.lang.Thread.*;

class ThreaDemo implements Runnable
{

    public void run()
    {
    try{String s=Thread.currentThread().getName();

        if(s=="squeek")
        Thread.sleep(5000);

        else
        {for(int i=0;i<5;i++)
            System.out.println(i+" ");
         }
        System.out.println(Thread.currentThread());
      }
    catch(Exception e)
      {}
    }

}

public class runnDemo extends ThreaDemo
{

    public static void main(String arg[])
    {
    ThreaDemo r=new ThreaDemo();
    Thread t=new Thread(r);
    t.setName("squeek");
    t.start();

    Thread t1=new Thread(r);
    t1.setName("quack");
    t1.start();

    }

}
hvt - 23 Feb 2007 13:04 GMT
On Feb 23, 5:34 pm, divyatiwari...@gmail.com wrote:
> Can we not use the getName() method  to schedule the threads??
>
[quoted text clipped - 41 lines]
>
> }

Replace if(s=="squeek") to if(s.equals("squeek")), ur program ll wrk
fine with this chg!
Proton Projects - Moin - 23 Feb 2007 13:11 GMT
On Feb 23, 5:34 pm, divyatiwari...@gmail.com wrote:
> Can we not use the getName() method  to schedule the threads??
>
[quoted text clipped - 41 lines]
>
> }
Hi,

if(s=="squeek")
>                  Thread.sleep(5000);

Need to be changed to
if(s.equals("squeek"))
>                  Thread.sleep(5000);

Try this u will get a delay....so that quack will get executed first
and then the squeek

Bcoz String comparison need to be done by using equals method...

Check this link for more info

http://access1.sun.com/FAQSets/newtojavatechfaq.html#9

Regards
Moin..
divyatiwari123@gmail.com - 26 Feb 2007 07:36 GMT
Hey Thanks guys. It worked.
divyatiwari123@gmail.com - 26 Feb 2007 07:39 GMT
Hey Thanks guys. It worked. forgot the String comparison part while
writing :) .


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.