请给我一些关于计时器编码的示例以及它在NetLogo上的工作方式

时间:2016-11-08 14:20:09

标签: netlogo

我正在考虑使用指定的时间段在指定颜色的补丁上停止Turtle的代码。但是,它仍然无法成功。也许计时器很有用。请给我一些关于计时器编码的示例,以及它在NetLogo上的工作方式。

以下网址是类似的问题,但几乎没有具体的代码示例。

How do I create a timer on netlogo?

1 个答案:

答案 0 :(得分:1)

我认为你得到了一些downvotes,因为它有点过于开放的问题,并不是很清楚。

您可以通过创建全局

来制作计时器
   public void myMethod(int batchSize) {
    // Send a JMS message with a POJO
    LOGGER.trace("Calling JMS method...");
    final JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
    jmsTemplate.convertAndSend("runJob", batchSize);
}

@JmsListener(destination = "runJob")
private void runJob(final int batchSize) {
    LOGGER.debug("Calling runJob with batchSize {}", batchSize);
    List<MyEntity> myEntities = myRepository.findAll();
    LOGGER.debug("{} entities retrieved from the DB", myEntities.size()); // Prints the actual number of entities in my DB
    for(Entity entity : entities){
        LOGGER.debug("Entity name {}", entity.getName()); // Prints entity name
        LOGGER.debug("Entity first collection's value {}", entity.getMyList().get(0).toString()); // org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: ..., could not initialize proxy - no Session
    }
}

// -----------------------
// Full code of my repository -> The implementation is generated by spring-data http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
public interface MyRepository extends org.springframework.data.jpa.repository.JpaRepository<MyEntity, Long>{}

并且每次打勾,在go命令期间增加它

Job myJob = dispatcher.newJobBuilder()
    // the JobService that will be called
    .setService(MyJobService.class)
    // uniquely identifies the job
    .setTag("my-unique-tag")
    // one-off job
    .setRecurring(false)
    // don't persist past a device reboot
    .setLifetime(Lifetime.UNTIL_NEXT_BOOT)
    // start between 0 and 60 seconds from now
    .setTrigger(Trigger.executionWindow(0, 60))
    // don't overwrite an existing job with the same tag
    .setReplaceCurrent(false)
    // retry with exponential backoff
    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
    // constraints that need to be satisfied for the job to run
    .setConstraints(
        // only run on an unmetered network
        Constraint.ON_UNMETERED_NETWORK,
        // only run when the device is charging
        Constraint.DEVICE_CHARGING
    )
    .setExtras(myExtrasBundle)
    .build();

只需根据需要修改即可。如果您遇到更多麻烦,请回复一下特定答案,并简要介绍一下您是否有问题的代码。