Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pl/SQL Procedure timeout

Posted on 2001-08-20
9
Medium Priority
?
3,191 Views
Last Modified: 2008-02-01
I have a PL/SQL procedure that calls an external C function. The external C function has a socket interface to another program and waits to receive information on the socket. After receiving the information it passes the information back to the procedure by reference variables. However, I want to setup a timeout on my PL/SQL procedure so that after 60 seconds, if it doesn't return any values to me I can kill the procedure. Is there any way to implement timeouts in my PL/SQL procedure?
0
Comment
Question by:arpanshah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Accepted Solution

by:
ser6398 earned 400 total points
ID: 6406863
You could create a job (using DBMS_JOB package) that kills the session, but it would not just halt the procedure.  I think you will find it difficult to just kill the procedure.

Given your setup, I would recommend that the external C function keep track of the time and return NULLs (or an error condition) back to the stored procedure if it has not received the info after 60 seconds.
0
 

Author Comment

by:arpanshah
ID: 6406900
The C function I have calls the socket recv() function which just waits till it gets some info over the socket. I cannot implement a timeout there cause I have no control over the socket recv() function.

Does, PL/SQL allow implementing timeouts in anyway? The problem is i could have several different instances of this procedure running at the same time and right now the database CPU just shoots up since the process is waiting infinitely to get a response.

Any other suggestions?

Thanks.
0
 
LVL 5

Expert Comment

by:ser6398
ID: 6406968
C functions allow threads.  You could create a thread to call the socket.  If the thread doesn't respond within 60 seconds, the main program could kill the thread.

This type of advanced programming is not available in a PL/SQL program.  You have many more options available to you in C than PL/SQL.

The only other way I can think of to do this would be to create a separate procedure that runs in a different session.  The main procedure could communicate with the second procedure through DBMS_PIPE.  The second procedure would call the C program.  If it doesn't respond back within 60 seconds, the main procedure could kill the session of the second procedure.  Sounds complex, but I think it could work.

When it comes down to it, C is a much more advanced programming language than PL/SQL, giving you more options.  Since you are already going through a C program, I recommend that you put this type of advanced stuff in the C program instead of in PL/SQL.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:jtrifts
ID: 6409190
In terms of PL/SQL, there is already a pre-defined exception called TIMEOUT_ON_RESOURCE (Ora-00051 SQLCODE -51).  

Speak to your DBA...you may be able to set the applicable DB value for this and use a WHEN TIMEOUT_ON_RESOURCE exception handler in your procedure.

0
 
LVL 5

Expert Comment

by:sora
ID: 6417101
You can use Oracle AQ for this kind of async requirement.

1. create a AQ
3. A Pro*C program periodically looks at the queue or stays eternally connected to the queue (This is not polling! The AQ will push info to the recipient)

This Pro*C program can then get info from the socket and place it into a queue from where the pl/sql procedure will pick it up.

This is easy to set up and maintain.

AQ can provide you with timeouts, expiry of messages placed in the queues, delay times etc.


sora
0
 
LVL 5

Expert Comment

by:sora
ID: 6417106
sorry, the step 3 should actually be step 2...:-)


sora
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7034725
Please update and finalize this old, open question.  Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,
Moondancer - EE Moderator

P.S.  Please click your Member Profile, expand View Question History to navigate and update all your open and locked questions.
0
 
LVL 4

Expert Comment

by:jtrifts
ID: 7036642
recommend Points to ser6398.
regards,
JT
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7039565
Thank you very much, JT, this has been finalized.
Moondancer - EE Moderator
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question