package com.hrfax;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@RunWith(SpringRunner.class)
@SpringBootTest
public class RestTempTest {
private static int count = 100;
private static CountDownLatch countDownLatch = new CountDownLatch(count);
@Test
public void test1() throws InterruptedException{
for (int i=0;i<count;i++){
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.start();
countDownLatch.countDown();
}
Thread.currentThread().join();
}
public class MyRunnable implements Runnable{
@Override
public void run() {
try {
countDownLatch.await();
}catch (Exception e){
}
// 發送Http請求
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> list = new ArrayList<>();
list.add(new FastJsonHttpMessageConverter());
restTemplate.setMessageConverters(list);
// restTemplate.getForObject("","");
}
}
}