-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTradeExpriyUpdateService.java
More file actions
37 lines (28 loc) · 1.1 KB
/
Copy pathTradeExpriyUpdateService.java
File metadata and controls
37 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.ashwin.trade.main;
/**
* This is a Service class where i have used Timer object to schedule tasks.
The task is scheduled to run every 5 minutes by calling timer.schedule(task, 0, 300000) to update the Expiry flag of trade.
This could also be implemented using Cache and do operations on TradeStore Cache
*/
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class TradeExpriyUpdateService {
private static TradeStore tradeStore ;
public static void main(String[] args) {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
updateTrades();
}
};
timer.schedule(task, 0, 300000);
}
private static void updateTrades() {
List<Trade> tradesWithLessMaturityDate;
tradesWithLessMaturityDate = tradeStore.getTradesWithLessMaturityDate();
for (Trade trade : tradesWithLessMaturityDate) {
trade.setExpired(true);
}
}
}