zainali5120
2020-10-14 32b5de4af771edfaa67197808882512ca7e30120
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.xcong.excoin;
 
import com.xcong.excoin.modules.coin.dao.OrderCoinsDao;
import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
import com.xcong.excoin.modules.coin.service.OrderCoinService;
import com.xcong.excoin.trade.CoinTrader;
import com.xcong.excoin.utils.RedisUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
@Slf4j
@SpringBootTest
public class TradeTest {
 
    @Resource
    private OrderCoinService orderCoinService;
 
    @Resource
    OrderCoinsDao orderCoinsDao;
    @Resource
    RedisUtils redisUtils;
 
    @Test
    public void buy(){
        redisUtils.set("ROC_NEW_PRICE",new BigDecimal("12.33"));
    }
 
    public static void main(String[] args) throws InterruptedException {
        // 测试两个地方
        List<String> list  = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        // 开一个线程
        Thread thread = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(1000);
                synchronized (list){
                    Iterator<String> iterator = list.iterator();
                    while (iterator.hasNext()){
                        System.out.println("线程里"+iterator.next());
                        iterator.remove();
                    }
                }
 
            }
        });
        thread.start();
        synchronized (list){
            Iterator<String> iterator = list.iterator();
            while (iterator.hasNext()){
                Thread.sleep(1000);
                System.out.println(iterator.next());
            }
        }
 
        //
    }
}