java 引用队列_Java中的方法队列
我的目標是在擴展Thread的類中包含一個方法調用隊列,該類的run方法每15秒將一次方法調用從隊列中彈出一次.可以在龐然大物的開關盒中使用Strings,int或chars以一種可遮蓋的方式完成此操作,但是我想知道是否還有其他人對此問題有更好的解決方案.
看起來像這樣嗎?
public class Potato extends Thread{
Queue methodsQueue = new LinkedList();
public Potato(){}
run(){
methodsQueue.poll();//This would execute a method
}
//Methods of this class...
}
解決方法:
您可以使用接口包裝要調用的方法:
public interface MethodWrapper {
void execute();
}
public class Potato extends Thread{
Queue methodsQueue = new LinkedList<>();
public Potato(){}
run(){
methodsQueue.poll().execute();
}
//Methods of this class...
}
標簽:multithreading,queue,java
來源: https://codeday.me/bug/20191118/2026770.html
總結
以上是生活随笔為你收集整理的java 引用队列_Java中的方法队列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 实现自旋锁_java自旋锁的代
- 下一篇: java最少有多少线程_【并发编程】一个