Skip to content

Instantly share code, notes, and snippets.

@keita03301995
Created December 25, 2017 22:05
Show Gist options
  • Save keita03301995/899ac0c47b4da1efc6eafea11217950c to your computer and use it in GitHub Desktop.
Save keita03301995/899ac0c47b4da1efc6eafea11217950c to your computer and use it in GitHub Desktop.
java thread
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main extends Thread{
int i = 100;
public static void main(String[] args) throws Exception {
Main main1 = new Main();
Main main2 = new Main();
main1.start();
main2.start();
}
public void run() {
add();
}
public synchronized void add(){
for(;i < 110; i++){
i++;
System.out.println(getName() + ":" + i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment