Guest User

Untitled

a guest
Jul 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. public class Lesson2 {
  2. private static int i;
  3.  
  4. public static void main(String[] args) {
  5. Thread t1 = new Thread(new Thread2());
  6. Thread t2 = new Thread(new Thread2());
  7. t1.start();
  8. t2.start();
  9. try {
  10. t1.join();
  11. t2.join();
  12. } catch (InterruptedException e) {
  13. e.printStackTrace();
  14. }
  15. System.out.println(i);
  16. }
  17.  
  18. static void incr() {
  19. i++;
  20. }
  21. }
  22.  
  23. class Thread2 implements Runnable {
  24. @Override
  25. public void run() {
  26. synchronized ( ЧТО ТУТ ПИСАТЬ??? ) {
  27. for(int i=0; i<2000; i++) {
  28. Lesson2.incr();
  29. }
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment