由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - L家coding question一问
相关主题
弱弱的问个C++用priority_queue定义min heap的问题一道经典涉及多线程,互斥访问的面试题
fb国内申请的曲折经历+电面到底什么是priority queue啊?
请教F最近超爱的面试题任务安排的follow up怎么做这个实现的话 用什么设计模式比较好?有没有大概给写个例子。
Facebook Interview QuestionsAn interview question of finding the median in a moving window.
面试用C++, heap 怎么办?帮我看下这是份什么工作,不是骗钱的吧?
G电面的一个题我也来贡献一下亚马的题
leetcode 上的k way mergeMathWorks 面经
Pure Storage面经any open source project for this problem?
相关话题的讨论汇总
话题: task话题: sleeptime话题: isrunning话题: public
进入JobHunting版参与讨论
1 (共1页)
l****c
发帖数: 782
1
就是按照时间顺序执行Task那道题,我收集了一些答案自己写了一下,
还请大牛多多多多的指点下,有没有问题。
多谢,多谢!
public class ProcessingQueueTest extends Thread {
//用个minHeap存Tasks
private Queue Tasks = new PriorityQueue<>(new Comparator(){
public int compare(Task a, Task b) {
if (a.time < b.time) return -1;
else if (a.time > b.time) return 1;
else return 0;
}
});
private boolean isRunning = true;
// 加Task进Heap
public void addTask(Task task) {
synchronized (this.Tasks) {
Tasks.add(task);
this.Tasks.notifyAll();
}
}
// 停止run
public void stopRunning() {
synchronized (this.Tasks) {
isRunning = false;
this.Tasks.notifyAll();
}
}
// run函数
public void run() {
while (isRunning) {
synchronized (this.Tasks) {
try {
long sleepTime = 6000;
if (!Tasks.isEmpty()) {
sleepTime = Tasks.peek().getExecuteMillis() - System
.currentTimeMillis();
}
if (sleepTime > 0) {
this.Tasks.wait(sleepTime);
}
} catch (InterruptedException ex) {
Logger.getLogger(ProcessingQueueTest.class.getName()).
log(Level.SEVERE, null, ex);
}
if (!this.Tasks.isEmpty()) {
Tasks.poll().execute();
}
}
}
}
}
r*******g
发帖数: 1335
2
哪道题?谢谢
l****c
发帖数: 782
3
就是那道写class实现task按照其定义的时间执行啊。
有人会吗?还请多指教!
1 (共1页)
进入JobHunting版参与讨论
相关主题
any open source project for this problem?面试用C++, heap 怎么办?
VMWare Interview questionG电面的一个题
贡献个面试题,目前狗狗都没找到.....leetcode 上的k way merge
问大家一个cpp中function pointer的问题Pure Storage面经
弱弱的问个C++用priority_queue定义min heap的问题一道经典涉及多线程,互斥访问的面试题
fb国内申请的曲折经历+电面到底什么是priority queue啊?
请教F最近超爱的面试题任务安排的follow up怎么做这个实现的话 用什么设计模式比较好?有没有大概给写个例子。
Facebook Interview QuestionsAn interview question of finding the median in a moving window.
相关话题的讨论汇总
话题: task话题: sleeptime话题: isrunning话题: public