简体   繁体   English

Spring Boot Schedule增量

[英]Spring Boot Schedule increment

I have one method for creating object. 我有一种创建对象的方法。 I put a schedule to create object on every second. 我制定了一个时间表来每秒创建对象。 In the object I have a parameter Time. 在对象中,我有一个参数Time。 Is it possible to increment the time on every created object. 是否有可能增加在每个创建的对象上的时间。 For example: First object time - 100000 例如:第一个对象时间-100000

Second object time - 103600 第二对象时间-103600

Third object - 107200 第三个对象-107200

Fourth object - 110800 第四个对象-110800

and etc 等等

This is the method that i have 这是我的方法

@Scheduled(fixedDelayString = "${fixedDelay}", initialDelayString = "${initialDelay}")
public SomeObject createSomeObject() {
    SomeObject obj1 = new SomeObject();
    String epoch1 = Long.toString(Timestamp.valueOf(rf.getStartDate()).getTime() / 1000);
    time1= Long.valueOf(epoch1);
    obj1.setTime(time1);       
    list.add(obj1);   
    return obj1;   
}

In my case i want to increment the value of time1 for 3600 and every object to have bigger value for 3600 than the object before him. 在我的情况下,我想为3600增加time1的值,并且每个对象的3600值要比他之前的对象大。

To set the time as an instance variable: 要将时间设置为实例变量:

final SomeObject someObject = new SomeObject();
someObject.setTime(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));

If you need different units of time, convert accordingly with TimeUnit . 如果需要不同的时间单位,请使用TimeUnit进行相应的转换。

For a static variable, you would want to call a setter method to set your class variable instead: 对于静态变量,您可能想调用setter方法来设置类变量:

SomeObject.setTimeStamp(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM