473,769 Members | 5,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lock issues in db2

1 New Member
Hi,

I'm new to DB2 and have little knowledge on database.

i'm facing a Spin lock issue in db2..

Thread here am talking is Java thread..(Sepear te process)

The spin Lock is acquired to ensure Same thread Can’t be stated again.
In our Application each thread is mapped to row .So lock is acquired on a row.

The issues in Db2.

1.We can acquire a Row Level Lock using for update. But it will release the lock when we use commit or rollback, we can’t use this because in our application we are doing multiple commits on that after acquiring a lock,,

2.There is another methodology available to achieve this is Cursor with Hold, if we use cursor with hold then it will maintain the lock even we used commit or rollback until we close the cursor.
So i try to implement this

We have multiple threads each thread have lock, So we need to Multiple cursor .Each cursor will hold a lock on each thread,..

The problem here is we don’t know how many number of threads required its dynamic so number of Cursor’s needed also Dynamic. (Each thread is to mapped to a cursor)
So we have to create a cursor Name Dynamically and close the same..
How to achieve this
1.Create 2 procedure one for acquire a lock (Create a cursor) and another to release the lock (Close the cursor)
2.Change the name of the cursor dynamically in the proc .


The Cursor Name creation dynamically using Java its failed Because Declare statement of Cursor can only be embedded in an application program. It is not an executable statement.
It must not be specified in Java. So i'm not proceeding to execute from java.

The option we have is to create a cursor name dynamically in a proc for acquiring and releasing the locks.

Sample Cursor :


CREATE PROCEDURE FCZ221k1.ACQURI NG_LOCK1 (IN RUNDATE CHAR , IN STREAMNO NUMERIC(10))
BEGIN
DECLARE C1_streamno CURSOR WITH HOLD FOR SELECT * FROM FCZ221K1.BatchP rocessResult where rundate=RUNDATE FOR UPDATE;
Open C1_ streamno;
END;

Converted to Dynamic cursor name as per the example i found in net.

CREATE PROCEDURE FCZ221k1.ACQURI NG_LOCK1 (IN streamno VARCHAR(120) ,IN processdate VARCHAR(36) )
LANGUAGE SQL
BEGIN
DECLARE EX_IMMD_VAR2 VARCHAR(4000) ;
DECLARE EX_IMMD_STMT2 STATEMENT ;
BEGIN

SET EX_IMMD_VAR2 = 'CREATE CURSOR ' || cur_streamno || 'CURSOR WITH HOLD FOR SELECT * FROM FCZ221K1.BatchP rocessResult where rundate=RUNDATE FOR UPDATE' ;
PREPARE EX_IMMD_STMT2 FROM EX_IMMD_VAR2 ;
EXECUTE EX_IMMD_STMT2;
END ;
End;

It’s also giving this error

SQL0312N The host variable "<host-name>" is used in a dynamic
SQL statement, a view definition, or a trigger
definition.

Explanation:

The host variable "<host-name>" appears in the SQL statement, but
host variables are not allowed in dynamic SQL statements, in the
SELECT statement of a view definition, or in the triggered action
of a trigger definition.

The statement cannot be processed.

User Response:

Use parameter markers (?) instead of host variables for dynamic
SQL statements. Do not use host variables and parameter markers
in view or trigger definitions.

sqlcode : -312

sqlstate : 42618

I’m not sure whether we can create a cursor name dynamically or not…

Please guide me on this…

Regards
Senthil
Jul 26 '08 #1
0 2820

Sign in to post your reply or Sign up for a free account.

Similar topics

6
437
by: n_o_s_p_a__m | last post by:
I have seen some debate but am not clear on what the problematic implications of the expression lock(this) are. Microsoft seems to advocate it, but others seem to be against it. Pros and cons? -KJ
0
3169
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and implementation, data abstraction layer. But because each data adapter in the implementation layer has a connection object that opens and closes as needed, I found I got several errors from the Jet engine when there were simultaneous connections to...
2
2699
by: Fernando Rodríguez | last post by:
Hi, I've been reading the multithreading tutorial at http://www.yoda.arachsys.com/csharp/threads/locking.shtml (thanks Jon :-) and there's one thing I don't understand. Why do have to pass a parameter to lock, Monitor.Enter() and Monitor.Exit()? Why is it necessary to create a new readonly variable for this purpose? (see below, counterLock)
2
2899
by: Kevin Frey | last post by:
Hello, I've been reading that ASP.NET serialises (ie. processes one at a time) HTTP requests if two simultaneous requests need to access the same session state. It also makes note that ASP.NET tries to reacquire a lock on the session state every 1/2 second until the timeout is reached, and then it will forcibly release the previous users lock and take the lock for itself. What is this timeout figure?
5
4068
by: Bob Bins | last post by:
Is there a way to create a shared lock using the Monitor class or any other synchronization class in .NET? So I have one resource that may have multiple threads using it at once but a second thread that when called must have exclusive access and cause the other threads to wait. I can't figure out how to do this with .Net. Thanks.
4
5668
by: misterutterbag | last post by:
Hi. Given the following: ---------------- String lockSubscriptionQuery = "SELECT subscriptionId FROM subscription WHERE subscriptionId = ? FOR UPDATE"; pStmt = conn.prepareStatement(lockSubscriptionQuery);
7
2245
by: Troels Arvin | last post by:
Hello, Some users are frustrated by DB2 locking their database operations (most recently: a table drop took forever, probably because of a lock). The natural and sane question I'm being asked: Is there a way for a user to see if a query is stuck waiting for a lock, or if it's simply taking a while to execute? As far as I can see, an ordinary user cannot get this kind of
2
2626
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will write text into a text file. // sample code FileLogger logger = LogFactory.Get_Logger(); logger.Log("Message here");
11
7986
by: fritzcwdev | last post by:
I have a class as follows: public class OperationFeedback { DateTime _startTime; public DateTime StartTime { get {
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.