view src/main/java/alice/test/concurrent/SleepCodeSegment.java @ 654:2fbd6ac705df

fix
author suruga
date Fri, 09 Feb 2018 19:48:43 +0900
parents aefbe41fcf12
children
line wrap: on
line source

package alice.test.concurrent;

import org.msgpack.type.Value;
import org.msgpack.type.ValueFactory;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class SleepCodeSegment extends CodeSegment {

    public Receiver ds1 = ids.create(CommandType.TAKE);

    private int num;

    public SleepCodeSegment(int i) {
        this.num = i;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("[CodeSegment-" + num + "] Hello, World!");
        try {
            Value i = ds1.getVal();
            if (i == null)
                System.out.println("got null");
        } catch (Exception e) {
            System.out.println("got Exception : "+e);
        }

        ods.put("local", "finish", ValueFactory.createNilValue());
    }

}