package com.batttest;
|
|
import java.util.Date;
|
import java.util.Timer;
|
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executors;
|
|
import com.battmonitor.base.AppParam;
|
import com.battmonitor.base.Com;
|
import com.battmonitor.data.BattData_RT;
|
import com.battmonitor.data.BattData_RT_Array;
|
import com.battmonitor.data.BattStatData;
|
import com.battmonitor.sql.MysqlConnPool;
|
import com.config.AppConfig;
|
|
public class BattDataTestPro_Thread extends Thread {
|
|
private ExecutorService m_WorkThreadPool;
|
private BattData_RT_Array m_Data;
|
private int BattTestCountMax = 10;
|
private int WorkThreadCountMax = 300;
|
//private MysqlConnPool m_Conn_Pool;
|
|
BattTestState m_BattTestState;
|
|
public BattDataTestPro_Thread(MysqlConnPool pool, AppParam param, AppConfig cfg, BattData_RT_Array data)
|
{
|
//m_Conn_Pool = pool;
|
BattTestCountMax = param.getBattTestGroupCountMax(AppParam.AppParam_Discharge);
|
WorkThreadCountMax = cfg.getWorkThreadCountMax();
|
m_Data = data;
|
|
m_WorkThreadPool = Executors.newFixedThreadPool(WorkThreadCountMax);
|
m_BattTestState = new BattTestState(BattTestCountMax);
|
}
|
//-----------------------------------------------------------------------------//
|
private class BattTestState{
|
|
private int[] battgroup_working_num;
|
|
public BattTestState(int size)
|
{
|
battgroup_working_num = new int[size];
|
for(int n=0; n<BattTestCountMax; n++)
|
{
|
battgroup_working_num[n] = -1;
|
}
|
}
|
|
public boolean putBattTesttingState( int index, boolean is_testting )
|
{
|
boolean res = false;
|
|
int search_index = 0;
|
for( search_index=0; search_index<battgroup_working_num.length; search_index++ )
|
{
|
if( index == battgroup_working_num[search_index] )
|
{
|
if(false == is_testting)
|
{
|
battgroup_working_num[search_index] = -1;
|
}
|
else
|
{
|
res = true;
|
}
|
break;
|
}
|
}
|
|
if(search_index >= battgroup_working_num.length)
|
{
|
if(true == is_testting)
|
{
|
for(int n=0; n<battgroup_working_num.length; n++)
|
{
|
if(battgroup_working_num[n] < 0)
|
{
|
battgroup_working_num[n] = index;
|
res = true;
|
break;
|
}
|
}
|
}
|
}
|
|
return res;
|
}
|
}
|
//-----------------------------------------------------------------------------//
|
@Override
|
public void run() {
|
System.out.println(this.getName() + " - BattDataTestPro_Thread Started By TimerTask ...");
|
Timer timer = new Timer();
|
MyBattTestTask myTask1 = new MyBattTestTask();
|
timer.scheduleAtFixedRate(myTask1, 1000, 1000); //ÈÎÎñ 1Ãëºó¿ªÊ¼½øÐÐÖØ¸´µÄ¹Ì¶¨ËÙÂÊÖ´ÐУ¨1ÃëÖÓÖØ¸´Ò»´Î£©
|
|
while(true)
|
{
|
try {
|
sleep(1000);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
class MyBattTestTask extends java.util.TimerTask{
|
String info = "MyBattTestTask By TimerTask";
|
|
@Override
|
public void run() {
|
// TODO Auto-generated method stub
|
try {
|
for(int n=0; n<m_Data.getItemCount(); n++) {
|
BattData_RT rt_data = m_Data.getItem(n);
|
/*
|
if(((rt_data.FBSDeviceId/1000000) != 910)
|
&& ((rt_data.FBSDeviceId/1000000) != 91)
|
&& ((rt_data.FBSDeviceId/10000) != 9600)
|
&& ((rt_data.FBSDeviceId/10000) != 9610)
|
&& ((rt_data.FBSDeviceId/100000) != 9616)) {
|
BattData_RT_SQL.get_GroupVolCurr_From_BattState_RT_RamDB_Table(m_Conn_Pool, rt_data);
|
}
|
*/
|
|
boolean need_to_store = rt_data.checkIfDataNeedStore();
|
|
if((rt_data.mTestData.newDataRecordTime.getTime()+15000) < rt_data.mTestData.recordTime.getTime()) {
|
rt_data.clearStoreDataBusyTag(); //´Ë´¦±ØÐëÊÍ·ÅÊý¾Ý¿â´æ´¢busy±êÖ¾.
|
continue;
|
}
|
|
boolean batt_is_testing = false;
|
if((BattStatData.BATTSTATE_CHARGE == rt_data.getBattTestType())
|
|| (BattStatData.BATTSTATE_DISCHARGE == rt_data.getBattTestType())
|
|| (BattStatData.BATTSTATE_MONITOR == rt_data.getBattTestType())
|
|| (true == need_to_store))
|
{
|
batt_is_testing = true;
|
}
|
|
if(true == m_BattTestState.putBattTesttingState(n, batt_is_testing))
|
{
|
if(true == need_to_store)
|
{
|
m_WorkThreadPool.execute(rt_data.mSqlTask);
|
}
|
}
|
else
|
{
|
rt_data.clearStoreDataBusyTag();
|
}
|
}
|
} catch (Exception e) {
|
System.err.println("MyBattTestTask: " + e.getMessage()
|
+ Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
}
|
}
|
|
public String getInfo(){
|
return info;
|
}
|
public void setInfo(String info){
|
this.info = info;
|
}
|
}
|
}
|