how to manage timeout in java

Discussion in 'Java' started by Pif, Nov 27, 2008.

  1. Pif

    Pif Guest

    Hello,

    I must call java method that does not support timeout feature.
    I would like to be able to manage timeout on this method.

    I'm in JDK 1.4.2 in a multi-user environment. So I would prefer not
    using one thread for each call. Can you suggest me solutions, ideas,
    or existing librairies ?

    Thanks a lot.
     
    Pif, Nov 27, 2008
    #1
    1. Advertising

  2. In article
    <>,
    Pif <> wrote:

    > Hello,
    >
    > I must call a Java method that does not a support timeout feature.
    > I would like to be able to manage a timeout on this method.
    >
    > I'm in JDK 1.4.2 in a multi-user environment. So I would prefer not
    > using one thread for each call. Can you suggest solutions, ideas,
    > or existing librairies?



    Well, you have to invoke the method from _some_ thread. You might look
    to see if the SwingWorker back-port is viable on 1.4.2.

    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
     
    John B. Matthews, Nov 27, 2008
    #2
    1. Advertising

  3. Pif

    Lew Guest

    Pif wrote:
    >> I must call a Java method that does not a support timeout feature.
    >> I would like to be able to manage a timeout on this method.
    >>
    >> I'm in JDK 1.4.2 in a multi-user environment. So I would prefer not
    >> using one thread for each call. Can you suggest solutions, ideas,
    >> or existing librairies?


    "So" you would prefer not to use a separate thread for each call? How does
    that follow?

    You should spawn the call in a separate thread and let that thread handle the
    timeout interrupt.

    John B. Matthews wrote:
    > Well, you have to invoke the method from _some_ thread. You might look
    > to see if the SwingWorker back-port is viable on 1.4.2.


    Assuming we're dealing with a Swing app.

    There is a backport of java.util.concurrent available for 1.4. GIYF.

    Why are you using an obsolete version of Java? The End-of-Life (EOL) period
    for 1.4 has expired and Sun no longer supports it.

    <http://java.sun.com/j2se/1.4.2/download.html>
    > On October 30, 2008 J2SE 1.4.2 reached the end of its service life (EOSL).


    Java 1.4 is nearly seven years old, eons in I.T. years. Even Java 5, over
    four years old itself, is in its EOL already.

    For God's sake, upgrade!

    --
    Lew
     
    Lew, Nov 27, 2008
    #3
  4. In article <ggmqcq$j4j$>, Lew <> wrote:

    > Pif wrote:
    > >> [...] So I would prefer not using one thread for each call. Can
    > >> you suggest solutions, ideas, or existing librairies?

    >
    > "So" you would prefer not to use a separate thread for each call? How does
    > that follow?
    >
    > You should spawn the call in a separate thread and let that thread handle the
    > timeout interrupt.
    >
    > John B. Matthews wrote:
    > > Well, you have to invoke the method from _some_ thread. You might look
    > > to see if the SwingWorker back-port is viable on 1.4.2.

    >
    > Assuming we're dealing with a Swing app.


    Excellent point. I see there's a new version, 1.2, as of July 25, 2008.

    > There is a backport of java.util.concurrent available for 1.4. GIYF.


    Thank you, good to know. I only recently wrapped-up my last 1.4.2
    project, but you never know. Some of the best paying clients are the
    most cuncatory about upgrades.

    [...]
    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
     
    John B. Matthews, Nov 27, 2008
    #4
  5. Pif

    Lew Guest

    John B. Matthews wrote:
    > Thank you, good to know. I only recently wrapped-up my last 1.4.2
    > project, but you never know. Some of the best paying clients are the
    > most cuncatory about upgrades.


    "Cuncatory" sounds so dirty.

    I don't find it in the dictionaries I have at hand. Could you define it,
    please, and provide a reference?

    At this point, if a client is "best-paying" and therefore presumably not
    unnecessarily stingy, they really should consider the risk of operating on an
    unsupported product. It's much higher now and increasing, even ignoring the
    manifest benefits of Java 5 and later.

    If they are running multi-threaded code, then they really have much higher
    risk with 1.4, given that it has the less mature and arguably incorrect memory
    model. Simply using the 1.4.2 version of java.util.concurrent isn't going to
    fix that.

    --
    Lew
     
    Lew, Nov 28, 2008
    #5
  6. In article <ggnhh5$mo5$>, Lew <> wrote:

    > John B. Matthews wrote:
    > > Thank you, good to know. I only recently wrapped-up my last 1.4.2
    > > project, but you never know. Some of the best paying clients are the
    > > most cuncatory about upgrades.

    >
    > "Cuncatory" sounds so dirty.
    >
    > I don't find it in the dictionaries I have at hand. Could you define it,
    > please, and provide a reference?


    I'd be delighted:

    <http://en.wiktionary.org/wiki/cunctatory>

    C.f. Fabius Maximus:

    <http://en.wikipedia.org/wiki/Fabius_Maximus>

    > At this point, if a client is "best-paying" and therefore presumably not
    > unnecessarily stingy, they really should consider the risk of operating on an
    > unsupported product. It's much higher now and increasing, even ignoring the
    > manifest benefits of Java 5 and later.


    They move, albeit slowly. EOL is a motive. I am heartened that it's
    relatively easy to build and test against several versions on the same
    development system.

    > If they are running multi-threaded code, then they really have much
    > higher risk with 1.4, given that it has the less mature and arguably
    > incorrect memory model. Simply using the 1.4.2 version of
    > java.util.concurrent isn't going to fix that.


    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
     
    John B. Matthews, Nov 28, 2008
    #6
  7. In article <>,
    "John B. Matthews" <> wrote:

    > In article <ggnhh5$mo5$>, Lew <> wrote:
    >
    > > John B. Matthews wrote:
    > > > Thank you, good to know. I only recently wrapped-up my last 1.4.2
    > > > project, but you never know. Some of the best paying clients are the
    > > > most cuncatory about upgrades.

    > >
    > > "Cuncatory" sounds so dirty.


    And misspelled, something I managed to do even after looking it up.

    > > I don't find it in the dictionaries I have at hand. Could you define it,
    > > please, and provide a reference?

    >
    > I'd be delighted:
    >
    > <http://en.wiktionary.org/wiki/cunctatory>


    [...]
    --
    John B. Matthews
    "What a dictionary this is. You have to know how something is spelt
    before you can look it up to see how it's spelt."
    --Annie Sullivan, The Miracle Worker (1962).
     
    John B. Matthews, Nov 28, 2008
    #7
  8. Pif

    Guest

    , Nov 30, 2008
    #8
  9. Pif

    Roedy Green Guest

    On Thu, 27 Nov 2008 13:29:33 -0500, "John B. Matthews"
    <> wrote, quoted or indirectly quoted someone who
    said :

    >Well, you have to invoke the method from _some_ thread. You might look
    >to see if the SwingWorker back-port is viable on 1.4.2.


    The basic idea is you need two threads, one to do the work, and one to
    wake up later and see if the first has completed as expected and if
    not, take evasive action.

    If you have a number of these to do, you can use a shared Timer to
    monitor timeouts on all the worker tasks.

    See http://mindprod.com/jgloss/thread.html
    http://mindprod.com/jgloss/timer.html

    This would be a good time to order a copy of Java Concurrency In
    Practice, in case you get stuck.

    http://www.amazon.com/gp/product/03...mp=1789&creative=9325&creativeASIN=0321349601

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    "Humanity is conducting an unintended, uncontrolled, globally pervasive experiment
    whose ultimate consequences could be second only to global nuclear war."
    ~ Environment Canada (The Canadian equivalent of the EPA on global warming)
     
    Roedy Green, Dec 2, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Johnson
    Replies:
    0
    Views:
    3,825
    Bob Johnson
    Aug 7, 2003
  2. Do
    Replies:
    2
    Views:
    6,451
  3. Guoqi Zheng
    Replies:
    4
    Views:
    13,123
    Guoqi Zheng
    Jun 3, 2004
  4. Martin Maercker

    JNI - how to manage C++ objects from Java?

    Martin Maercker, Jan 16, 2005, in forum: Java
    Replies:
    2
    Views:
    3,610
    Chris Uppal
    Jan 18, 2005
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,355
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page