• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Future timeout doesn't end the submit...Necessity of timeout in Future.get

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When i submit a future job and put a thread sleep say for 25 seconds in run method...

Future.get attempted with error with timeout say 3 seconds...

The future job resumes after 25 seconds..

1. Does timeout only applicable for Get? why?
2. Can we set a timeout for submit as well? if not, why java didn't consider that

Generally we would also like to set a timeout for a method execution instead of particular query

Also, how to terminate both application and db thread with one kill or one method

Thanks.
 
Saloon Keeper
Posts: 14488
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joseph Michael wrote:1. Does timeout only applicable for Get? why?


You can usually set a timeout on blocking methods. If a method doesn't block, then there is no point to setting a timeout.

2. Can we set a timeout for submit as well? if not, why java didn't consider that


I'm assuming you're referring to ExecutorService.submit(). What would it even mean to set a timeout on submit()? The method doesn't block.

Also, how to terminate both application and db thread with one kill or one method


What do you mean by db thread?

Usually it's a bad idea to terminate everything in one go. Processes should kill themselves after finishing their tasks. Why do you want to do this?
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan, the problem is

One of the SQL query takes time and we don't want any query to execute for more than 10 mins...However when the SQL takes too much time, we want to stop it from application and DB end...If i use Future.submit and executes a DB query...If we end up the hibernate session after future.cancel, will the DB thread will be killed. Or irrespective of killing the hibernate session or using future.cancel DB still executes the query in the DB side.

This arises the following questions

1. Will future.cancel kills the executing DB query in the DB
2. Will hibernate session end kills the executing DB query in the DB
 
Stephan van Hulst
Saloon Keeper
Posts: 14488
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joseph Michael wrote:One of the SQL query takes time and we don't want any query to execute for more than 10 mins...


Isn't the first solution to write a faster query?

If i use Future.submit and executes a DB query...


There is no such thing as Future.submit().

If we end up the hibernate session after future.cancel, will the DB thread will be killed.


Why cancel the future? Just supply Hibernate with a timeout from within your submitted task.

Will future.cancel kills the executing DB query in the DB


No. Future.cancel() just sets a cancelled flag and interrupts blocking method calls. It's up to your submitted task to handle interruptions properly.

2. Will hibernate session end kills the executing DB query in the DB


I think so, but have you read the Hibernate documentation?
 
Have you no shame? Have you no decency? Have you no tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic