/examples/kilim/examples/SimpleTask2.java

http://github.com/kilim/kilim · Java · 49 lines · 26 code · 7 blank · 16 comment · 2 complexity · 37418701cefce4f8644e2bf97e3011a3 MD5 · raw file

  1. /* Copyright (c) 2006, Sriram Srinivasan
  2. *
  3. * You may distribute this software under the terms of the license
  4. * specified in the file "License"
  5. */
  6. package kilim.examples;
  7. import kilim.ExitMsg;
  8. import kilim.Mailbox;
  9. import kilim.Pausable;
  10. import kilim.Task;
  11. /**
  12. * A slight extension to SimpleTask. This
  13. *
  14. * [compile] javac -d ./classes SimpleTask2.java
  15. * [weave] java kilim.tools.Weave -d ./classes kilim.examples.SimpleTask
  16. * [run] java -cp ./classes:./classes:$CLASSPATH kilim.examples.SimpleTask2
  17. */
  18. public class SimpleTask2 extends Task {
  19. static Mailbox<String> mb = new Mailbox<String>();
  20. static Mailbox<ExitMsg> exitmb = new Mailbox<ExitMsg>();
  21. public static void main(String[] args) throws Exception {
  22. Task t = new SimpleTask2().start();
  23. t.informOnExit(exitmb);
  24. mb.putnb("Hello ");
  25. mb.putnb("World\n");
  26. mb.putnb("done");
  27. exitmb.getb();
  28. System.exit(0);
  29. }
  30. /**
  31. * The entry point. mb.get() is a blocking call that yields
  32. * the thread ("pausable")
  33. */
  34. public void execute() throws Pausable{
  35. while (true) {
  36. String s = mb.get();
  37. if (s.equals("done")) break;
  38. System.out.print(s);
  39. }
  40. Task.exit(0); // Strictly optional.
  41. }
  42. }