自己設計的,不知道有沒有坑,慎用
@component
public
class
roundrobintaskserviceimpl
extends
abstractcloudwalkservice
implements
roundrobintaskservice}}
//3 維護預案和roi對映關係
set> roiset =
newhashset
<
>()
; roiset.
add(roilist)
; taskroimap.
put(cruisetask.
getid()
, roiset)
;//4 執行緒輪詢
taskexecutor.
execute
(new
runnable()
catch
(dataacces***ception e)
catch
(interruptedexception e)}}
);}/**
* 開啟並行任務
** @param cruisetask
*/@override
public
void
startparalleltask
(cruisetaskvo cruisetask)
} roiset.
add(roilist);}
//3 維護預案對應的roiset
taskroimap.
put(cruisetask.
getid()
, roiset)
;//4 開啟執行緒輪詢roiset
roiset.
parallelstream()
.foreach
(roilist -
>
taskexecutor.
execute
(new
runnable()
catch
(exception e)}}
));}
/** * 關閉預案
** @param taskid
*/@override
public
void
stoptask
(string taskid));
threaditerator.
remove()
;}}//2清空延時佇列
iterator
>> delayiterator = taskdelaymap.
entryset()
.iterator()
;while
(delayiterator.
hasnext()
)); delayiterator.
remove()
;}}//3 清空roilist
iterator
>>> roiiterator = taskroimap.
entryset()
.iterator()
;while
(roiiterator.
hasnext()
)}}catch
(exception e)
", e);}
logger.
debug
("終止當前輪詢的預案,taskid:"
+ taskid);}
/** * 獲取當前執行的點位中的roi(序列或並行)
** @param taskid
*/@override
public list
getcurrentroi
(string taskid));
cruisepointlist.
add(cruisepoint);}
});}
}}catch
(exception e)
return cruisepointlist;
}/**
* 輪詢roi
** @param taskid
* @param roilist
*/private
void
processtask
(string taskid, concurrentlinkedqueue
roilist)
throws dataacces***ception, interruptedexception
else
// 2 維護預案和延時佇列間的關係
delayqueue delayqueue =
newdelayqueue()
;if(!collectionutils.
isempty
(taskdelaymap.
get(taskid)))
else
// 3 預案輪詢
while
(roilist != null &&
!roilist.
isempty()
&&!thread.
currentthread()
.isinterrupted()
)catch
(dataacces***ception
| interruptedexception exception)
try thread.
sleep(1
);if(valid)
當前輪詢到的roi {}"
, taskid, jsonutils.
tojson
(cruisepointroi));
delayqueue.
put(delaytask)
; delayqueue.
take()
;if(!roilist.
isempty()
)}else
無效的roi {},不參與輪詢"
, taskid, jsonutils.
tojson
(pollroi));
roilist.
offer
(pollroi);}
}}catch
(interruptedexception exception)}}
}
StopWatch任務執行時間監控
在最近 codereview中,發現 中大量使用了stopwatch 這個類去監視執行的時間。這裡總結一下大概的介紹。stopwatch 在spring中和apache中均提供了類似的功能,這裡分別介紹一下。stopwath是apache commons lang包下的乙個任務執行時間監視器,具體位...
FreeRTOS任務執行時間資訊統計
以下兩個函式都是任務執行時間資訊統計函式 include sys.h include delay.h include usart.h include led.h include timer.h include key.h include string.h include freertos.h inc...
FreeRTOS任務執行時間資訊統計
相關巨集的設定 configgenerate run time stats 使能 portconfigure timer for run time stats 配置乙個高精度定時器 計數器提供時基 portget run time counter value 讀取時間值 實驗舉例 char runt...