fork download
  1. package test.java.oo;
  2.  
  3. import java.util.concurrent.Executors;
  4. import java.util.concurrent.ScheduledExecutorService;
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. import com.google.common.util.concurrent.ListeningScheduledExecutorService;
  8. import com.google.common.util.concurrent.MoreExecutors;
  9.  
  10. public class NonBlockingExcutor {
  11.  
  12. private static ListeningScheduledExecutorService mListeningScheduledExecutorService = null;
  13. private static ScheduledExecutorService mScheduledExecutorService = null;
  14.  
  15. private static boolean isTurnOn = false;
  16.  
  17. public static class doWork implements Runnable {
  18. private String name = null;
  19.  
  20. public doWork(String name) {
  21. this.name = name;
  22. }
  23.  
  24. @Override
  25. public void run() {
  26. if (isTurnOn) {
  27. System.out.println(name + " 完工!");
  28. } else {
  29. mListeningScheduledExecutorService.schedule(this, 1,
  30. TimeUnit.SECONDS);
  31. System.out.println(name + " 等待開工");
  32. }
  33. }
  34. }
  35.  
  36. public static void main(String[] args) {
  37. mScheduledExecutorService = Executors.newScheduledThreadPool(5,
  38. Executors.defaultThreadFactory());
  39. mListeningScheduledExecutorService = MoreExecutors
  40. .listeningDecorator(mScheduledExecutorService);
  41. for (int i = 1; i <= 9; i++) {
  42. mListeningScheduledExecutorService.submit(new doWork("任務" + i));
  43. }
  44.  
  45. // 打開電源的工作
  46. mListeningScheduledExecutorService.submit(new Runnable() {
  47. @Override
  48. public void run() {
  49. isTurnOn = true;
  50. }
  51. });
  52. }
  53.  
  54. }
  55.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:10: error: class NonBlockingExcutor is public, should be declared in a file named NonBlockingExcutor.java
public class NonBlockingExcutor {
       ^
Main.java:7: error: package com.google.common.util.concurrent does not exist
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
                                        ^
Main.java:8: error: package com.google.common.util.concurrent does not exist
import com.google.common.util.concurrent.MoreExecutors;
                                        ^
Main.java:12: error: cannot find symbol
	private static ListeningScheduledExecutorService mListeningScheduledExecutorService = null;
	               ^
  symbol:   class ListeningScheduledExecutorService
  location: class NonBlockingExcutor
Main.java:39: error: cannot find symbol
		mListeningScheduledExecutorService = MoreExecutors
		                                     ^
  symbol:   variable MoreExecutors
  location: class NonBlockingExcutor
5 errors
stdout
Standard output is empty