Example #1
0
  // From Mission
  @Override
  protected void initialize() {

    OutputStream os = null;
    try {
      os = Connector.openOutputStream("console:");
    } catch (IOException e) {
      throw new Error("No console available");
    }
    out = new SimplePrintStream(os);

    PeriodicEventHandler peh =
        new PeriodicEventHandler(
            new PriorityParameters(11),
            new PeriodicParameters(new RelativeTime(0, 0), new RelativeTime(500, 0)),
            new StorageParameters(10000, null),
            500) {

          int cnt;

          public void handleAsyncEvent() {

            InParam ip = new InParam();
            OutParam op = new OutParam();
            op.sb = new StringBuilder(30);

            Worker w = new Worker(ip, op);

            out.println("Ping " + cnt);
            ++cnt;

            // Generate more garbage
            for (int i = 0; i < 10; ++i) {
              // this would generate too much garbage in the initial private memory
              // w.run();
              ip.s = "iter ";
              ip.i = i;
              ManagedMemory.enterPrivateMemory(500, w);
              out.println(op.sb);
            }

            if (cnt > 5) {
              // getCurrentMission is not yet working
              single.requestTermination();
            }
          }
        };
    peh.register();
  }