Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Time Out With Normal Java Method

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Time Out With Normal Java Method

    Dear Team,
    I am calling here one third party jar file which has some code written which is internally doing some S2S call to get data some times this method is not returning result and all thread are blocked here.. can some any idea is there any way so that i can put time out in normal java method while calling... so if it is not returning result in 10 second then i can throw exception and handle it this situation....


    Please suggest....

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Time Out With Normal Java Method

    Some suggestions:
    The Timer class can be used to start a method after a fixed delay.
    The Thread class's sleep method can be used to stop execution for a fixed time.
    The Object class's wait method can be used to stop execution for a fixed time.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Out With Normal Java Method

    Thanks for reply..
    But don't you think if we have not received response from the method then all the threads getting blocked if i use Thread class's sleep or Object class's wait method... and also please suggest if i use object class wait method then how it is being notify?

    Can you help us to give some sample snippet here which will help to resolve our problem..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Time Out With Normal Java Method

    all the threads getting blocked
    Only the thread that calls the method will get blocked. The other threads should continue executing.

    Can you post the code you are trying to modify along with a description of where you want to change it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Out With Normal Java Method

    Thanks Norm,
    Is there any chances of deadlock occurred in case...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Time Out With Normal Java Method

    Yes it is possible for a deadlock.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Out With Normal Java Method

    Is there any other way without creating thread.. we can use any API or something else?

    I don't want to use thread here, causing it could raise deadlock condition...

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Time Out With Normal Java Method

    Is the problem code using methods that block? Can you change that code to use non-blocking methods? Or methods that time out.

    Most code of this type requires using multiple threads.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Out With Normal Java Method

    Can you help me here by sharing some code snippet to get idea how to i handle? If possible then asynchronous way..

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Time Out With Normal Java Method

    Sorry, I not really sure I have any code that does what you are trying to do.

    There are more people with code samples at this forum: http://www.coderanch.com/forums
    Try asking your question there.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to get normal html javascript function value to java code
    By Sri Ram in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 15th, 2014, 06:30 AM
  2. How to check PDF is 3D or Normal in JAVA.
    By Ravi_Patel in forum Member Introductions
    Replies: 1
    Last Post: July 14th, 2014, 06:07 AM
  3. Using Date() to get Start Time and Finish Time of a copyFiles method
    By dalythe in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 17th, 2013, 09:50 PM
  4. [SOLVED] Please help me first time user, and need help with a method
    By foresboo in forum What's Wrong With My Code?
    Replies: 16
    Last Post: February 12th, 2013, 04:36 PM
  5. How to Compare a Substring to a Normal White Space in Java
    By Indybones33 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 27th, 2012, 07:56 PM