Concurrent access using JDBC in Java - java

I'm developing a Java Desktop Application using JDBC, and I wanted to manage the concurrent access to the Database. Someone told me to use Sessions but after some research it turned out that Sessions are not possible in Desktop app.
This is why I'm asking for some help. You have any ideas on how to manage this thing.
Thanks

From what you described, I recommend you to check for SQL exceptions while trying to insert or update some row that may be already be changed by someone else. In that case maybe you should reload what your app shows to the user so they have up-to-date data. Another option is to show a user-friendly error.
If your app executes several queries (insert, update) in a row, I suggest using transactions. I think the easiest way to set them in a Desktop app is to use the Spring framework, if you are familiar with it.

It is not clear exactly what you mean by manage concurrent access - do you want to avoid multiple select queries to the DB? In that case using SELECT for UPDATE might be an option. If you are looking for more general method in limiting only single user to access the DB at any time, you will have to roll your own locking mechanism in the code I suppose.

So long as each Thread is using a different Connection, there should not be any concurrency issues in the JDBC. There are any number of ways to achieve this. e.g. ThreadLocal or a connection pool.
I don't see how a single desktop app can be accessed by many users. You can have many copies of a desktop app and each user has their own connections. This shouldn't cause an issue. You need to clarify what your concern is.

Related

Is it possible to create and schedule a background task in Java Hibernate/Spring MVC Web application?

I have been assigned to work in a project which was built by another developer. It uses Hibernate/Spring MVC technology in Java with MySQL is database server.
Previously, by the time the project went live the first time, there was not much data, so the performance was fine. Now our client is expanding their business. A lot of data was imported and thousands more will soon be imported. Many features in the website require multiple database transactions based on user input. Performing a lot of database operations each time they navigate between pages is nightmarish to them.
I'm thinking of declaring some static variables, then creating scheduled tasks to automatically load data into the variables so they can be used globally. I know how to do this with a desktop application but I don't know if it is possible in a MVC web application. Can anyone please help me? Thanks.
UPDATED: Another thing I forgot to mention is new data will be imported by our client's side everyday. I've made some analysis and see performance improvement can hardly be achieved via cache. The only solution I can think of is through background tasks but I'm not sure how can I achieve this.

Tools to Check Oracle database performance

I have an stand alone app which run several threads, for each thread there are a connection to the database, the business logic is to do some validations and send data to the database, it's too much information, about 2 millions rows in one hour.
So I need to know the database behaviour, the connections, sessions and everything, right know I'm using JVMonitor to check the app performance, now I need to check the database.
How can I check this? Is there a plug-in for Eclipse or anything like that?
Thanks in advance.
AWR and ASH reports along with v$ performance views. Integrated tools examples: Oracle Enterprise manager, method R and confio.

Alternatives to SQLite for Java that supports multi-user write

Does anyone know of a sqlite alternative for Java that would support multiple write(s) at the same time?
I'm aware of the option of checking to see if the database is available and pause the attempt to write until it can actually write. But still I'm looking for alternatives where I can really do concurrent writes.
Update (further explanation):
I'm setting up a system where there will be multiple users keying in a single database so I would naturally like the idea of being able to work non-stop instead of having to pause to wait for the database to be available for writing.
Take a look at H2 - it's feature rich embeddable file-based DB.

Network application

I'm developing a network application, which will handle a lot of transactions, so I'm using INNODB as storage engine & Transactions, so do I need to use a LockTable also?
As I know they don't work together. Please give me the best solution to do it.
Not sure why you are asking about table locking with respect to InnoDB, as it supports row-level locking. I would just focus on making sure your transactions are written correctly and let MySQL take care of the rest.

Synchronizing local database with remote database and vice versa

I am developing a web application with php that needs to synchronize a local mysql database that a java desktop version of the web application is interacting with. At the same time i also need the local db to synchronize with the remote db. How do i do this without using other software like MySQL Compare. I will really appreciate the help. Thanx guys.
You clearly have a significant architecture issue. It needs to be planned very well. Two-way replication clearly isn't going to work unless you have thought it out very carefully and understand how to do conflict resolution and what impact that will have on your application. In particular, you can forget using AUTO_INCREMENT.
For one-way replication, you can use mk-table-sync, or use mysql replication in some way (there are a variety of possiblities).
You can also run another mysql instance on the server, use mk-table-sync to periodically synchronise it locally, and use mysql replication on that. This has some benefits, particularly if there are some tables you don't want to replicate.
You really need to think about how it's going to work, if you plan to do two-way synchronisation. It is possible that you may end up writing custom code to do it, as the conflict resolution mechanism may mandate it.

Categories