fork download
  1.  
  2.  
  3. class J {
  4. public static void main(String args[]) throws InterruptedException {
  5. final Account a = new Account();
  6. Job r = new Job(a);
  7.  
  8. int n = 0;
  9. Thread[] threads = new Thread[n];
  10. for (int i = 0; i < n; ++i) {
  11. Thread t = new Thread(r);
  12. threads[i] = t;
  13. t.start();
  14. }
  15. for (Thread t : threads) {
  16. t.join();
  17. }
  18.  
  19. System.out.println(a.n);
  20. }
  21. }
  22.  
  23. class Job implements Runnable {
  24. Account a;
  25.  
  26. public Job(Account a) {
  27. this.a = a;
  28. }
  29.  
  30. public void run() {
  31. int dotori2 = ((int)(Math.random() * 10) + 1) * 1000;
  32. System.out.println(dotori2);
  33. try {
  34. Thread.sleep(1000);
  35. } catch(Exception e) {
  36.  
  37. }
  38. a.plus(dotori2);
  39. }
  40. }
  41.  
  42. class Account {
  43. int n = 0;
  44.  
  45. public synchronized void plus(int amount){
  46. if (amount > 0) {
  47. n -= amount;
  48. }
  49. }
  50. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
0