I was told to create a desktop application written in java, I chose JavaFX for creating rich UI.
I test my app with dummy data and it works fine, now I have to work with MongoDB which would be a local database in a machine on which the app would be installed. data is streaming and injected into the database within seconds, and every for example 2 seconds I have to query for newer data and show them in the app.
but I don't know how to make a data layer in my app that would communicate with the UI layer. (how to write POJO and DAO classes, make the data layer run in the background and not block the UI thread)
should I use Spring Boot to make my app? I have read that JavaFX and Spring Boot have their own application entry point
I have never got my hands dirty with the Spring framework.
actually it's the first time I'm creating a desktop app and I have no experience in working with MongoDB.
You can create a new Thread for your database access code, if you want. To do this, define a new Thread, and in the argument of the constructor, create a new (or use an existing) Runnable. Runnable is an interface which defines a simple run() method, so you can simply make an anonymous runnable. Make sure to call thread.start(), instead of thread.run()!
When you want to make updates to the UI from the new Thread you made, make sure to call Platform.runLater() or it won't let you do it. No threads besides the UI thread are allowed to update the UI, so Platform.runLater schedules a UI update on the UI thread.
So you can think of the process like this:
- UI element has an event triggered on it (like a button press)
- UI element schedules and launches a new Thread
- UI thread continues unblocked
- Database thread accesses MongoDB
- Database thread schedules a UI modification on the UI thread
- UI thread performs desired modification
POJO are plain old java objects. Essentially it's an object with no real custom behavior, it just has private fields and public getters/setters and the equals/hashcode method implemented. The POJO should be the model object that you want to store in your database. In AWS (which I have experience with) we convert those into a data transfer object which specifies the hash key and sort key, I imagine the DAO for mongodb is similar.
zeinab sheikhi wrote:actually it's the first time I'm creating a desktop app and I have no experience in working with MongoDB.
Then (in my opinion) it would be a bad idea to add Spring to the list of technologies you have to learn for this project. Stick with Zachary's suggestions, they look like a good outline for you to start working on.