Results 1 to 4 of 4
- 11-15-2011, 02:56 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 34
- Rep Power
- 0
Deleting data while it's modified by a thread
Hi,
i have entitys that periodically get data from a server on the internet. Each entity runs in a thread like this:
Java Code:scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { get data ... do something with data... ....
- 11-15-2011, 05:04 AM #2
Member
- Join Date
- Jul 2011
- Posts
- 34
- Rep Power
- 0
Re: Deleting data while it's modified by a thread
I use EclipseLink by the way.
If i just delete an entity while it is updating, i get an PersistenceException saying that a connection can't be closed while a transaction is active
- 11-15-2011, 09:37 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 34
- Rep Power
- 0
Re: Deleting data while it's modified by a thread
Nobody can help?
If my problem isn't clear please ask.
Here is a more detailed explanation:
- i have 2 tables in a Database (Stock and StockPrice)
- Stock has the fields stockid, stockname, currency, tickersymbol etc ...
- StockPrice has id, price of a stock, time of a Stock and as foreign key the stockid
- A StockPrice can't exist without a stockid
Every stock in the stock table now has a thread running to get the actual stockprice (from a server on the Internet) and save it in the table StockPrice.
To save it in the table a stockPrice has to have a stockid.
The problem i have now occurs when the user deletes a stock, cause then the Thread tries to insert a stockprice in Stockprice with the stockid null.
I don't really know now what's the right way to handle this situation. Should i try to immediately stop the Scheduler before i delete the Stock? Thus canceling the thread in the middle of doing something? And if yes how?
Or should i delete the Stock and try to handle the Exceptions the thread in execution is then throwing and then shutdown the scheduler normally (after finishing executing it's work) ?
- 11-23-2011, 08:18 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 65
- Rep Power
- 0
Re: Deleting data while it's modified by a thread
Databases has synchronization program that handles exceptions such as write before read .......
Just look PL/SQL :> to write trigger or procedure
you have to write trigger don't use thread to change that values. Trigger will solve your problem
if you write trigger then database automatically changes the other tables according to relation between tables.
You have to write correct trigger ofcourse.
if this is not your solution, then you can catch error and ignore that case
try{
insertStockprice();
}catch(Exception e)//I do not know the exact exception so you can see in error log
{
//Not to do :> just blank: It will skip this insertion. Also you can kill the thread in here it's your choice
}
I hope it helps
Similar Threads
-
problem in deleting data
By harsimran05 in forum JDBCReplies: 1Last Post: 10-12-2011, 10:03 PM -
deleting the data in the column model
By bigj in forum New To JavaReplies: 0Last Post: 02-08-2010, 09:15 AM -
Modified Pixels
By monkey04 in forum Java 2DReplies: 1Last Post: 03-12-2009, 09:15 AM -
JSP Last Modified Date
By thagentleman in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-18-2008, 05:52 AM -
data from the main/GUI thread to another runnin thread...
By cornercuttin in forum Threads and SynchronizationReplies: 2Last Post: 04-23-2008, 11:30 PM
Bookmarks