• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help with Multithreading a MVC Application  RSS feed

 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me start by somewhat explaining the application.....

The only way a user can manipulate data is through buttons that use AbstractActions or JTable with AbstractTableModel. The abstract actions are also used as a controller to update the view based on the model or add and remove data from the files using the file controller and then update the model. The file controller is designed to write and read the data using csv files. The model uses a Map<Supplier, TreeSet<Product>> for the data structure. This model uses the basic add, remove and get methods to manipulate the data. The application will eventually support multiple users that will use the same CSV files.


I haven't done threads in over a year and have pretty much forgot a lot of what I learned.


A few questions I have at this moment:

Threads and setValueAt method within the AbstractTableModel?

Should I create a thread for each abstract action or text action that manipulates data?

Should I just synchronize the add and remove methods of the model?

Shouldn't I just use threads for really reading and writing to the csv files?

When would you use include view update logic in a thread (EDT)?



Here is some code....Any improvements needed please throw that in there with your comment as well!!!


This controller reads and writes to the csv files and then updates the model.....



This is the model for the application.....I feel a little iffy about the Map variable name that I used.....


Here is an example of an abstract action that updates the view and uses the csv file controller. The class is static because it is in a class that is grouped to a certain panel and the fact that I love the design concept (static factories).



 
Paul Clapham
Sheriff
Posts: 22375
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're asking questions like that then the absolutely first thing you should do is to read the Swing Concurrency Tutorial. Don't even think of thinking about those questions until you've done that.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:If you're asking questions like that then the absolutely first thing you should do is to read the Swing Concurrency Tutorial. Don't even think of thinking about those questions until you've done that.


So in reality I really won't need multithreading for this application except possibly one area. When I start the application all of the data from the files will be updated into the model. Would a swing worker thread be beneficial here or should I not show the GUI until the data is loaded? Other than that most of the processes will be relatively quick.....

If the application doesn't use multithreading would I still use within the main method:

SwingUtilities.invokeLater(new Runnable
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if multiple users are changing data in the csv files at the same time? The files will be on a operating system domain (LAN). Couldn't this cause corruption in the data? Is this possible without a specific application (Center point for all users similar to a server application) for file manipulation?
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which case it is the csv files which are the problem. Why are you using csv files rather than a database? That way you can use transactions for everything.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:In which case it is the csv files which are the problem. Why are you using csv files rather than a database? That way you can use transactions for everything.


The size of the data is too small for a database. The maximum amount of data that will be used and this is probably over exaggerating some, 25 files with 200 lines each. Plus the client doesn't want a database. I did bring this up as it would provide more growth.....
 
Paul Clapham
Sheriff
Posts: 22375
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Sexton wrote:What if multiple users are changing data in the csv files at the same time? The files will be on a operating system domain (LAN). Couldn't this cause corruption in the data?


It could mess up the files, yes. But that's a problem entirely separate from threading in Swing applications and (as you suggest) might have to be addressed by writing a centralized web application which controls access to this data.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!