Service层
package com.example.thead.service;
import com.example.thead.task.FileTask;
import org.springframework.stereotype.Service;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Service
public class TaskImpl {
private static final ExecutorService executorService = new ThreadPoolExecutor(8,15,60L, TimeUnit.SECONDS,new LinkedBlockingQueue<>());
public void testTask(String id){
executorService.submit(new FileTask(id));
}
}
Task层
package com.example.thead.task;
import com.example.thead.context.SftpContext;
import lombok.extern.slf4j.Slf4j;
import java.util.UUID;
@Slf4j
public class FileTask implements Runnable{
private String id;
public FileTask(String id){
this.id=id;
}
@Override
public void run() {
String value =getVal(this.id);
System.out.println("vv==="+value);
}
public String getVal(String id){
String tId = id+"-"+Thread.currentThread().getId();
String value = SftpContext.getVal(tId);
// String value = FileTask.getVal(tId);
if(null==value){
System.out.println("new uid======"+tId);
value=UUID.randomUUID().toString();
// FileTask.setMap(tId,value);
SftpContext.put(tId,value);
}
return value;
}
}