| | |
| | | package com.thread.devs;
|
| | |
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | |
|
| | | import com.mode.Device_Inf;
|
| | |
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | RecordRealData real = new RecordRealData(pool, device);
|
| | | new Thread(real).start();
|
| | | |
| | | Manage_Simul_Motor_Thread_SQL.insertOrUpdateMotor_State_Table(pool, state);
|
| | | while(true) {
|
| | | try {
|
| | |
| | | Manage_Simul_Motor_Thread_SQL.updateMotor_State_Table(pool, state);
|
| | |
|
| | | Thread.sleep(1000);
|
| | | } catch (InterruptedException e) {
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
| | | state.motor_state = Manage_Util.CreateSwitchRanDom();//'电机状态',
|
| | | }
|
| | |
|
| | | public class RecordRealData implements Runnable{
|
| | | public MysqlConnPool pool;
|
| | | public Device_Inf device;
|
| | |
|
| | | |
| | | public RecordRealData(MysqlConnPool pool,Device_Inf device) {
|
| | | this.pool = pool;
|
| | | this.device = device;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | Date last = new Date(0,0,0);
|
| | | while(true) {
|
| | | Date now = new Date();
|
| | | try {
|
| | | Manage_Simul_Motor_Thread_SQL.createTb_Motor_State_RealData_Table(pool, state.device_id, now);
|
| | | Manage_Simul_Motor_Thread_SQL.createTb_Motor_State_RealData_Table(pool, state.device_id, tomorrow(now));
|
| | | |
| | | if((now.getTime()-last.getTime())>=1000){
|
| | | Manage_Simul_Motor_Thread_SQL.insertMotor_State_RealData_Table(pool, state);
|
| | | |
| | | last = now;
|
| | | } |
| | | Thread.sleep(200);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 返回明天日期
|
| | | * @param today
|
| | | * @return
|
| | | */
|
| | | public Date tomorrow(Date today) {
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(today);
|
| | | calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
|
| | | return calendar.getTime();
|
| | | }
|
| | | }
|