Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: My First Thread Program

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My First Thread Program

     
    public class PingPong2 implements Runnable
    {
    private String Ping;
    private int delay;
     
    public PingPong2(String a, int b)
    {
    Ping=a;
    delay=b;
    }
     
    public void run()
    {
    try
    {
    for(; ;)
    {
    System.out.print(Ping + "\t");
    Thread.sleep(delay);
    System.out.println("CurrentThread: "+Thread.currentThread());
    }
    }catch(InterruptedException e)
    {
    System.out.println("Exception: "+e);
    }
    }
     
     
     
    public static void main(String[] args)
    {
    PingPong2 rn1 = new PingPong2("Ping1", 5000);
    PingPong2 rn2 = new PingPong2("Pong2", 200);
    Thread t1 = new Thread(rn1);
    Thread t2 = new Thread(rn2);
    t1.start();
    t2.start();
    }
     
    }
    Last edited by Norm; April 8th, 2014 at 02:05 PM. Reason: Spaces removed from code tag


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: My First Thread Program

    Did you have a question?

    The posted code has lost all its indentations for nested statements.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My First Thread Program

    Quote Originally Posted by Norm View Post
    Did you have a question?

    The posted code has lost all its indentations for nested statements.
    No, I don't have any Q.

Similar Threads

  1. Replies: 3
    Last Post: September 17th, 2021, 12:10 AM
  2. How to categorise a daemon thread to specific thread in java?
    By rajasekhar_b in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 10th, 2014, 07:55 AM
  3. supermarket checkout program in thread
    By Veeramanikandan in forum Threads
    Replies: 3
    Last Post: November 12th, 2013, 03:06 PM
  4. Replies: 1
    Last Post: September 24th, 2013, 04:18 PM
  5. Idle thread in multithreading program.
    By Endian in forum Threads
    Replies: 5
    Last Post: May 15th, 2012, 02:02 PM