Solved

Pl/SQL Procedure timeout

Posted on 2001-08-20
9
2,895 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 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

730 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