Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

thread in java


public class MyThread extends Thread {
    private final String name;

    public MyThread(String name) {
        this.name = name;
    }

    public void run() {
        try {
            for (; ; ) {
                System.out.println(name);
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            System.out.println("sleep interrupted");
        }
    }

    public static void main(String[] args) {
        Thread t1 = new MyThread("First Thread");
        Thread t2 = new MyThread("Second Thread");
        t1.start();
        t2.start();
    }
}

Comment

thread in java

//if your project supports java8, you can implement with lambda function
//for android
new Thread(() -> {
        // do background stuff here
        runOnUiThread(()->{
            // OnPostExecute stuff here
        });
    }).start();
Comment

create thread java

class RunnableObject implements Runnable {
   private Thread t;
   private String threadName;
   
   RunnableObject( String name) {
      System.out.println("Creating " +  threadName );
      threadName = name;
      t = new Thread (this, threadName);
   }
   
   public void run() {
      System.out.println("Running " +  threadName );
   }
   
   public void start () {
      System.out.println("Starting " +  threadName );
      t.start ();
   }
}

public class TestThread {

   public static void main(String args[]) {
      RunnableObject R1 = new RunnableObject( "Thread-1");
      R1.start();
   }   
}
Comment

Java Thread Example Using the Thread Class

class SoftHuntThread
{    
public static void main(String argvs[])  
{     
Thread thread= new Thread("Softhunt Thread");   
thread.start();    
String string = thread.getName();  
System.out.println(string);  
}  
}
Comment

java thread

public static void main(String[] args {
   ...
   Thread t1= new Thread(...);
   t1.start();
   ...
}
Comment

Java Thread

class Java_Thread extends Thread{  
public void run(){  
System.out.println("thread is running...");  
}  
public static void main(String args[]){  
Java_Thread thread =new Java_Thread ();  
thread.start();  
}  
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to check when edittext clicked android 
Java :: java scanner int to string 
Java :: object type in java 
Java :: Odd or even program in java using a mod operator 
Java :: android check file extension 
Java :: check if LinkedList is empyth java 
Java :: java array merge 
Java :: netbeans android sdk location 
Java :: why are my if statements not working with inputs in java 
Java :: java session timeout 
Java :: JFrame change outline 
Java :: java regex for ip address 
Java :: android list tostring 
Java :: how to convert a arraylist to array in java 
Java :: Printing cube root of a number in java 
Java :: java clear scanner 
Java :: display 2d array 
Java :: java string split underscore 
Java :: how to upload image from android app to server 
Java :: java instanceof operator 
Java :: reverse a doubly linked list 
Java :: How to change integers into float in java 
Java :: how to create textview in java android 
Java :: Java Remove Elements from HashSet 
Java :: Java @Deprecated annotation 
Java :: java stream findany 
Java :: super class tostring java 
Java :: declare matrix in java 
Java :: splash full screen android 
Java :: method 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =