Skip to content

Instantly share code, notes, and snippets.

@slmanju
Created October 28, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slmanju/42962b2998dd85a16d6cdafad9f713c8 to your computer and use it in GitHub Desktop.
Save slmanju/42962b2998dd85a16d6cdafad9f713c8 to your computer and use it in GitHub Desktop.
multithreading with java
public class Concurrent {
public static void main(String[] args) {
Thread runner1 = new Thread(new ThreadRunner("R1"));
Thread runner2 = new Thread(new ThreadRunner("R2"));
runner1.start();
runner2.start();
}
}
class ThreadRunner implements Runnable {
private String name;
ThreadRunner(String name) {
this.name = name;
}
public void run() {
for (int i = 0; i < 10; ++i) {
System.out.printf("Name: %s %d %n", this.name, i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment