Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package __SERVER;
- public class Server {
- public static void main(String[] args) {
- ThreadB b = new ThreadB();
- b.start();
- synchronized (b) {
- try {
- System.out.println("Ждем пока поток b выполнится...");
- b.wait();
- } catch (InterruptedException e) {
- }
- System.out.println("Total равно: " + b.total);
- }
- }
- private static class ThreadB extends Thread {
- int total;
- public void run() {
- synchronized (this) {
- for (int i = 0; i < 100; i++) {
- total += i;
- }
- notifyAll();
- try {
- sleep(10000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment