Jump to content

barlaw

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by barlaw

  1. In JAVA threads are programmed like this:

    class ThreadDemo extends Thread {
       private Thread t;
       private String threadName;
       
       ThreadDemo( String name){
           threadName = name;
           System.out.println("Creating " +  threadName );
       }
       public void run() {
          System.out.println("Running " +  threadName );
          try {
             for(int i = 4; i > 0; i--) {
                System.out.println("Thread: " + threadName + ", " + i);
                // Let the thread sleep for a while.
                Thread.sleep(50);
             }
         } catch (InterruptedException e) {
             System.out.println("Thread " +  threadName + " interrupted.");
         }
         System.out.println("Thread " +  threadName + " exiting.");
       }
       
       public void start ()
       {
          System.out.println("Starting " +  threadName );
          if (t == null)
          {
             t = new Thread (this, threadName);
             t.start ();
          }
       }
    
    }
    
    public class TestThread {
       public static void main(String args[]) {
       
          ThreadDemo T1 = new ThreadDemo( "Thread-1");
          T1.start();
          
          ThreadDemo T2 = new ThreadDemo( "Thread-2");
          T2.start();
       }   
    }
    

    Executing above code will produce following result:

    Creating Thread-1
    Starting Thread-1
    Creating Thread-2
    Starting Thread-2
    Running Thread-1
    Thread: Thread-1, 4
    Running Thread-2
    Thread: Thread-2, 4
    Thread: Thread-1, 3
    Thread: Thread-2, 3
    Thread: Thread-1, 2
    Thread: Thread-2, 2
    Thread: Thread-1, 1
    Thread: Thread-2, 1
    Thread Thread-1 exiting.
    Thread Thread-2 exiting.
    

    Is this possible in LabVIEW OO? If so where can I find some more information/ sample code?

    I would like to have two classes, the thread and the class that starts the thread(s).

    Thanks in advance!
     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.