Solved

Pl/SQL Procedure timeout

Posted on 2001-08-20
9
2,737 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
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Accepted Solution

by:
ser6398 earned 100 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need help with Oracle syntax 4 41
Oracle Pivot 2 32
Oracle RMAN Database Restore 5 30
Convert Oracle data into XML document 2 37
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now