i**********e 发帖数: 1145 | 1 Try this:
It will use the high resolution performance clock if available (for both
windows/*nix platform), otherwise it will roll back to the non-high
resolution timer.
/**
* Timer class definition file.
*
* Provides basic timer functionality which calculates running time for
certain
* part of your program. Very useful for analyzing algorithm running time.
* After a Timer object is created, calling the Start() member function
starts
* the timer running. The Stop() member function stops the timer... 阅读全帖 |
|
l****c 发帖数: 782 | 2 就是按照时间顺序执行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) {
synchron... 阅读全帖 |
|
m*****n 发帖数: 204 | 3 package test;
import java.util.concurrent.Semaphore;
import test.IElements.WaterElements;
public class H2OExtraThread {
private final Semaphore sema = new Semaphore(0);
private volatile boolean isRunning = true;
// Called by the control thread
private void controllerRun() {
while (isRunning) {
try {
sema.acquire(WaterElements.totalAtomsPerMolecule);
} catch (InterruptedException e) {
continue;
... 阅读全帖 |
|
m*****n 发帖数: 204 | 4 package test;
import java.util.concurrent.Semaphore;
import test.IElements.WaterElements;
public class H2OExtraThread {
private final Semaphore sema = new Semaphore(0);
private volatile boolean isRunning = true;
// Called by the control thread
private void controllerRun() {
while (isRunning) {
try {
sema.acquire(WaterElements.totalAtomsPerMolecule);
} catch (InterruptedException e) {
continue;
... 阅读全帖 |
|
r**u 发帖数: 130 | 5 no isRunning() member function? |
|