英文:
JavaFX program - How to keep TableView data synchronized amount different client computers?
问题
I'm new to Java and just started writing some JavaFX applications.
My current project is to write an application for a consulting company that stores a list of customers, adds them to a queue, and serves them one by one. There are a few staff members, and they will run a copy of the application I write on their PCs.
What I've done so far:
-
Created Customer.class to handle personal info and stored them in a MySQL db.
-
Created Staff.class to handle staff info.
-
Created Service.class to handle the types of services available for the customers.
-
Created Consultation.class to handle info of a particular consultation, such as date of consultation, the customer being served, which staff is providing service, the services offered, and the outcome.
-
Created an ObservableArrayList
, stored the data in the MySQL db, and displayed the data on a TableView on each client's PC.
What I want to do is, after a staff member edits the data in the list, the changes will be automatically updated on the TableView of other client PCs.
The possible solutions I can think of include:
Option 1:
Program the application to query the db regularly for an update. This method is simpler to implement, but I don't want to keep the MySQL server busy with non-stop queries from a number of clients. I don't want any delay between data write and updates on other clients. There are more than 10 clients. If each client updates once a second, that will mean at least 10 queries per second, and the server will never rest. I don't want to put any stress on the server's hard disk.
Option 2:
Program the application to broadcast a message every time after they write data to the db, and other clients query the database every time they receive a broadcast. I prefer to do it this way, but I'm not familiar with network programming. That means I'll have to spend some time on it before I can continue the project.
Which of the above is a better choice? Is there another way to keep the TableView on the clients synchronized?
英文:
I'm new to Java and just started writing some JavaFX applications.
My current project is to write an application for a consulting company that store a list of customers, add them to a queue and serve them one by one. There are a few staffs and they will running a copy of the application I write on their PC.
What I've done so far:
-
create Customer.class to handle personal info and store them in a MySQL db
-
create Staff.class to handle staff info
-
create Service.class to handle kind of services are available for the customers
-
create Consultation.class to handle info of a particular consultation such as date of consultation, customer being served, which staff is providing service, the services offered and the outcome
-
create an ObservableArrayList<Consultation>, store the data in the MySQL db, and display the data on a TableView of each client PC
What I want to do is, after a staff editing the data in the list, the changes will be updated on the TableView of other client PCs automatically.
The possible solutions I can think of includes:
Option 1
Program the application to query the db regularly for an update.
This method is more simple to implement, but I don't want to keep the MySQL server busy by non-stop querys from a number of clients. I do not want any delay between data write and update on other clients. There are more than 10 clients. If each client update once a second, that will mean at least 10 queries per second and the server will never rest. I don't want to put any stress on the server's harddisk.
Option 2
Program the application to broadcast a message every time after they write data to the db and other clients query the database every time they receive a broadcast. I prefer do it this way but I'm not familiar with network programming. That will mean I'll have to spend some time on it before I can continue the project.
Which of the above is a better choice? Is there other way to keep the TableView on the clients keep synchronized?
答案1
得分: 1
请提供您要翻译的具体内容,我将帮您进行翻译。
英文:
> Which of the above is a better choice? Is there another way to keep the TableView on the clients keep synchronized?
Before choosing - you may consider optimizing them,
-
Option 1 seems quite expensive as it has to request frequently. But you can optimize it using connection-pool and specifying certain time-interval(minimum 10 sec) to fetch the data.
-
Option2 is much more convincing as it applies the lazy-loading concept. You may consider looking socket programming to notify all clients to fetch data.
It's quite hard to say which one is the better option - somehow, I prefer to go with the first approach if your application may insert data frequently, otherwise go with the second one.
An alternative solution - listening to the data changes
Here are some QA, these solutions may help you to implement your requirement.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论