JavaFX程序 – 如何在不同客户端计算机之间保持TableView数据同步?

huangapple go评论103阅读模式
英文:

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:

  1. Created Customer.class to handle personal info and stored them in a MySQL db.

  2. Created Staff.class to handle staff info.

  3. Created Service.class to handle the types of services available for the customers.

  4. 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.

  5. 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:

  1. create Customer.class to handle personal info and store them in a MySQL db

  2. create Staff.class to handle staff info

  3. create Service.class to handle kind of services are available for the customers

  4. 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

  5. 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,

  1. 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.

  2. 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.

huangapple
  • 本文由 发表于 2020年1月3日 22:35:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定