Created
December 25, 2017 22:05
-
-
Save keita03301995/899ac0c47b4da1efc6eafea11217950c to your computer and use it in GitHub Desktop.
java thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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