我怎样才能每秒钟更新一次视图以反映实时的变化?

时间:2022-07-11 15:21:32

I'm writing an app for a manager to keep track of the goings-on of a factory that uses machines. Could I make a Swing interface that updates from an SQL database and constantly shows who is logged into each machine, the status of each machine and how many things are in the queue of each machine? All the machine info is in the database.

我正在为一位经理编写一个应用程序,以跟踪一个使用机器的工厂的运行情况。我是否可以创建一个Swing接口,从SQL数据库中更新,并不断显示登录到每台机器的人、每台机器的状态以及每台机器的队列中有多少东西?所有的机器信息都在数据库中。

In short, how can I refresh a view every second so that it will reflect the real-time status of the factory floor?

简而言之,我如何每一秒钟刷新一次视图,以反映工厂层的实时状态?

2 个解决方案

#1


3  

Using the Java timer class at 1000 milliseconds and querying the mysql database. Provided your db latency is low, you should be able to update 1/second.

在1000毫秒时使用Java timer类并查询mysql数据库。如果您的db延迟很低,您应该能够更新1/秒。

#2


2  

Or use a ScheduledExecutorService

或者使用ScheduledExecutorService

#1


3  

Using the Java timer class at 1000 milliseconds and querying the mysql database. Provided your db latency is low, you should be able to update 1/second.

在1000毫秒时使用Java timer类并查询mysql数据库。如果您的db延迟很低,您应该能够更新1/秒。

#2


2  

Or use a ScheduledExecutorService

或者使用ScheduledExecutorService