I have a web application based on Java EE and MYSQL.
The problem which I am facing right now is, there is an event getting fired online, which is updating a table entry for a large number of rows.
There is also a batch job scheduled in the environment, say for every 6 minutes, which is also updating the same table entry, as mentioned above.
So the situation is that, when the online event is getting fired in the time range of the batch run, the table is getting locked.
So, experts please provide your ideas, on how to prevent the lock to take place.
Looks like a design issue,take a look at using temporary tables.
Related
I am trying to write ATDDs for a batch job. The job has the following scenario:
It checks the DB and if some event has been recorded 7 days back, it will pick up that event and reprocess. Here, 7 days is the pre-requirement to process it. While reprocessing, the system will interact with multiple services.
So, here I have to create this scenario through my ATDDs and want to verify if the job ran successfully.Means my ATDDs have to create specific data with the creation date as 1 week older.
I have enough experience with ATDDs with Cucumber+Java so want to work on same. Could someone give some idea whether it could be achieved?
At the moment, I have a little JavaFX app that generates reports and statistics from the data on a remote MySQL-Server. I use EclipseLink for persistence. Since the access is read-only and the data doesn´t always need to be fresh, I thought I could speed things up by using an embedded DB (H2) that can be synchronized to the remote server when and if the user wishes to. The problem is, I don´t have a clue how to go about it.
What I came up with so far, is to execute mysqldump, make a dump of the remote server and execute the resulting SQL script locally. This is surely far from elegant, so: Is there a patent solution for this task?
Well, 50 tables possible have a considerable amount of relations, this can be tricky... As far as I know there is nothing that automate this for you or something like that. Very possible that you will have to create your own logic to that. When I did something like what are you trying to do I used the logic of "last update", like, the local data have the timestamp of the time it was last synced with the remote, and the remote data have the timestamp of the last time the data was updated there (himself on the table, or even a relation to it like a One-To-One). Having that data, every time the local user enter a part of the system that can be outdated, the client connect to the server and check if the last update timestamp is bigger that the local synced timestamp, if so, it updates the full object and relation. I consumed some time to develop but at the end worked like a charm. There may be some other way to do it, but this was the way I found at the time. Hope it helps you with your problem.
I have an issue with my app that is a stand alone Java application. I am using the core java, JDBC and javafx 2.1. I have to show users the number of rows present in a table in the database. For that I am firing SELECT COUNT(*) FROM SCHEMA.TABLENAME in my java code and displaying results in a tableView (javafx 2.1). As my database contains large number of tables with large rowcount (number of rows in a table), this process takes a lot of time (30 mins.). With that approach, my tableview is stuck and users will be unable to proceed further until the process finishes. I am using the normal Thread.sleep() in my code.
I would like to run the process in the background so that users will be able to do other tasks. Users should be notified once the process is done. I have tried with javafx 2.1 asynchronous but couldn't solve the issue.
Please give me some piece of code that will interact with the db in the background in javafx 2.1.
Thanks& Regards
Salamat
Use a Task as in the JavaFX Concurrency Tutorial.
This allows you to safely execute code on a background thread and not block the main UI thread.
Here is some sample code for accessing a database using a Task.
I read several doc that told me that if i want to make a realtime application, i should use MySQL Cluster. So this is what i done.
But i wasn't able to find how to make a JTable updated each time a value in the MySql Cluster was updated.
Do you have any links or example that can help with my issue.
Thanks in advance.
Is your java app the one performing the updates on the database or is possible for other processes to make changes?
If only your app is making the changes, you can fire an event every time an update/insert/delete happens that will refresh the table.
If another process can make changes to the database then you'll need a background thread that will occasionally query the database for changes.
In terms of displaying the data in the JTable, you'll probably need a pretty customized TableModel to cache data, etc.. to minimize the effects of refreshing if the data is changing rather frequently
Problem solved: Thanks guys, see my answer below.
I have a website running in Tomcat 5.5 hooked up to a MySQL5 database using Hibernate3.
One record simply refuses to keep any changes performed on it. If I change the record programmatically, the values revert back to what they were previously.
If I manually modify the record in the database, the values will revert (seemingly once the webapp accesses them).
I have tried stopping Tomcat and changing the values manually then starting Tomcat again. Checking the database, the values remain changed after Tomcat has started the webapp but will revert back again once I load the site.
I have also tried deleting the Tomcat work folder for the webapp and the .ser cache file.
I have also checked the code for the values that are being reverted to and cannot find them.
I have only noticed it on this one particular record.
Edit: I've just had a look at the SQL output from Hibernate using hibernate.show_sql=true. There is an update query logged for the table my row is in. Does anyone know how to resolve the ? for the columns to actual values?
You could temporarily enable the mysql query logging and see exactly what sql statement altered the value. Since you say it changes immediately after the server starts you should be able to figure out the statement pretty quickly.
http://dev.mysql.com/doc/refman/5.0/en/query-log.html
To answer your question:
Does anyone know how to resolve the ?
for the columns to actual values?
You can do this with p6spy. Instructions for how to set this up in a Spring app are available here.
However, I think there's a mistake in these instructions, the file they refer to as p6spy.log should actually be name p6spy.properties.
It's getting close to halloween, so you have to expect this sort of thing (plus it was just a full moon), but I'd keep looking for the culprit in the web application ... it HAS to be there. A couple values I'd immediately search for in the webapp source code:
The id of the record being changed.
The value that's being written into
the record.
Good luck ... these can be real bears to find!
This smells a little like a test-case firing on start up that modifies the row to what it expects it to be before testing.
Add a trigger BEFORE UPDATE, check row id, raise an SQL error if it matches your magic row.
Then check the generated stacktrace, walk the code and locate the piece that updates the row.
Thanks to everyone for the help. All of the suggestions came in handy for tracking it down.
I've managed to find out what was causing it. Bad database design, multiple data models and Hibernate makes for some nasty stuff. Another table had the value stored and that class was extending a base class with the same value.
Time to look at doing some normalisation.