Question : thread in java
Answered by : innocent-iguana-w9xvl0bpxtb1
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(); }
}
Source : https://devarama.com/questions/2865315/Threads-in-Java | Last Update : Sun, 10 Apr 22
Question : thread in java
Answered by : shashank-mistry
//if your project supports java8, you can implement with lambda function
//for android
new Thread(() -> { // do background stuff here runOnUiThread(()->{ // OnPostExecute stuff here }); }).start();
Source : | Last Update : Tue, 01 Feb 22
Question : threads in java
Answered by : davide-santoro
class MyThread extends Thread { int stuff public ServerThread(int stuff) { this.stuff = stuff; } // this method will be called by the start method when a new thread will run public void run() { this.myCode(); } //it's recommended to put the code to run in a separated method public void myCode() { //your code }
}
public class MyExample { public static void main(String[] args) { int stuff = 10; MyThread myThread = new MyThread(stuff); /*.start will start a new thread, moves it from New State to Runnable state and will execute the run method*/ myThread.start(); }
}
Source : | Last Update : Fri, 02 Dec 22
Question : java thread
Answered by : dennis-woodtli
public static void main(String[] args { ... Thread t1= new Thread(...); t1.start(); ...
}
Source : | Last Update : Thu, 04 Mar 21
Question : Java Thread
Answered by : unsightly-unicorn-1cjun9udyrbh
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();
}
}
Source : https://softhunt.net/what-is-a-thread-in-java/ | Last Update : Thu, 16 Dec 21