473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

configuring java stored procedure so only 1 sp call processed at a time

Hi all,

I'm sure this is really really easy but I do need some help.

I'm writing a java stored prcedure to manage the assignment of IP
addresses to mac addresses for a network device database I've got.
Basically a user fills in a template detailing information about
themselves, the location of the pc and its mac address. The SP takes
this input info and scans a database table that stores the assigned ip
addresses in a subnet looking for the next free ip address and then
performs a record insert using the free address. Obviously you don't
want two instances scanning the same subnet for the next free ip
address at the same time.

Once the SP has been called, I want any other requests to the sp to be
queued up while that particular invocation has completed - just in
case there are 2 people trying to register information on the same
subnet. When the call completes, the next request in the queue can be
processed.

How do i implement the above

TIA
Alex
Nov 12 '05 #1
5 2043

"Alex" <A.******@hull.ac.uk> wrote in message
news:b2**************************@posting.google.c om...
Hi all,

I'm sure this is really really easy but I do need some help.

I'm writing a java stored prcedure to manage the assignment of IP
addresses to mac addresses for a network device database I've got.
Basically a user fills in a template detailing information about
themselves, the location of the pc and its mac address. The SP takes
this input info and scans a database table that stores the assigned ip
addresses in a subnet looking for the next free ip address and then
performs a record insert using the free address. Obviously you don't
want two instances scanning the same subnet for the next free ip
address at the same time.

Once the SP has been called, I want any other requests to the sp to be
queued up while that particular invocation has completed - just in
case there are 2 people trying to register information on the same
subnet. When the call completes, the next request in the queue can be
processed.

How do i implement the above

I don't think this is really a DB2 issue as much as a Java issue. Have a
look at the synchronized keyword in Java for one possible approach. Also,
consider the idea of using multiple Java threads. A discussion of this
approach occurs in the Java Tutorial starting at
http://java.sun.com/docs/books/tutor...ithreaded.html

The following article (and its sequels) consider both approaches:
http://www-106.ibm.com/developerwork...ry/j-threads1/

Rhino
Nov 12 '05 #2
Ian
Alex wrote:
Hi all,

I'm sure this is really really easy but I do need some help.

I'm writing a java stored prcedure to manage the assignment of IP
addresses to mac addresses for a network device database I've got.
Basically a user fills in a template detailing information about
themselves, the location of the pc and its mac address. The SP takes
this input info and scans a database table that stores the assigned ip
addresses in a subnet looking for the next free ip address and then
performs a record insert using the free address. Obviously you don't
want two instances scanning the same subnet for the next free ip
address at the same time.


You don't need to do anything special.

DB2 will handle this for you with row and/or table locks, provided
you're using the proper isolation level (the default, CS, should do
the trick) and you are handling the search/insert as a single
transaction.

Good luck,

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #3
Ian <ia*****@mobileaudio.com> wrote in message news:<40********@corp.newsgroups.com>...
Alex wrote:
Hi all,

I'm sure this is really really easy but I do need some help.

I'm writing a java stored prcedure to manage the assignment of IP
addresses to mac addresses for a network device database I've got.
Basically a user fills in a template detailing information about
themselves, the location of the pc and its mac address. The SP takes
this input info and scans a database table that stores the assigned ip
addresses in a subnet looking for the next free ip address and then
performs a record insert using the free address. Obviously you don't
want two instances scanning the same subnet for the next free ip
address at the same time.


You don't need to do anything special.

DB2 will handle this for you with row and/or table locks, provided
you're using the proper isolation level (the default, CS, should do
the trick) and you are handling the search/insert as a single
transaction.


Hmmm as a single transaction, don't think my sql is up to that.

At the moment I've gor a procedure that returns the ip address to use.
The internals of this function connects to the database ,performs a
table search returning a resultset containing an ascending ordered
list of all the ip addresses in a particular subnet. I then start at
the 1st one and read through the returned values checking that they
are in sequence (2,3,4, etc ). When I find a gap, I use the "prev"
value + 1

This value is then used in a separate insert statement to add data to
the table.

If there's a way of combining the two I'd certainly like to know.

alex
Nov 12 '05 #4
"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message news:<1J********************@news20.bellglobal.com >...
"Alex" <A.******@hull.ac.uk> wrote in message
news:b2**************************@posting.google.c om...
Hi all,

I'm sure this is really really easy but I do need some help.

I'm writing a java stored prcedure to manage the assignment of IP
addresses to mac addresses for a network device database I've got.
Basically a user fills in a template detailing information about
themselves, the location of the pc and its mac address. The SP takes
this input info and scans a database table that stores the assigned ip
addresses in a subnet looking for the next free ip address and then
performs a record insert using the free address. Obviously you don't
want two instances scanning the same subnet for the next free ip
address at the same time.

Once the SP has been called, I want any other requests to the sp to be
queued up while that particular invocation has completed - just in
case there are 2 people trying to register information on the same
subnet. When the call completes, the next request in the queue can be
processed.

How do i implement the above

I don't think this is really a DB2 issue as much as a Java issue. Have a
look at the synchronized keyword in Java for one possible approach. Also,
consider the idea of using multiple Java threads. A discussion of this
approach occurs in the Java Tutorial starting at
http://java.sun.com/docs/books/tutor...ithreaded.html

The following article (and its sequels) consider both approaches:
http://www-106.ibm.com/developerwork...ry/j-threads1/

Rhino


Many thnaks for this, some weekend reading methinks
:-))
Nov 12 '05 #5
Alex wrote:
Ian <ia*****@mobileaudio.com> wrote in message
news:<40********@corp.newsgroups.com>...
Alex wrote:
> Hi all,
>
> I'm sure this is really really easy but I do need some help.
>
> I'm writing a java stored prcedure to manage the assignment of IP
> addresses to mac addresses for a network device database I've got.
> Basically a user fills in a template detailing information about
> themselves, the location of the pc and its mac address. The SP takes
> this input info and scans a database table that stores the assigned ip
> addresses in a subnet looking for the next free ip address and then
> performs a record insert using the free address. Obviously you don't
> want two instances scanning the same subnet for the next free ip
> address at the same time.


You don't need to do anything special.

DB2 will handle this for you with row and/or table locks, provided
you're using the proper isolation level (the default, CS, should do
the trick) and you are handling the search/insert as a single
transaction.


Hmmm as a single transaction, don't think my sql is up to that.

At the moment I've gor a procedure that returns the ip address to use.
The internals of this function connects to the database ,performs a
table search returning a resultset containing an ascending ordered
list of all the ip addresses in a particular subnet. I then start at
the 1st one and read through the returned values checking that they
are in sequence (2,3,4, etc ). When I find a gap, I use the "prev"
value + 1

This value is then used in a separate insert statement to add data to
the table.


All this is done inside the procedure?

Do you execute a COMMIT or ROLLBACK statement somewhere in between? If not
then, you already do this in a single transaction (aka unit of work).

p.s: It might be a good idea to read a SQL book that covers the basics of
SQL statements and transactions.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dimitris | last post by:
I'm using ADO.NET to call a stored procedure that runs the "BACKUP" command on selected databases. Is there any way I can capture the text output of the stored proc and return it to ADO.NET for...
3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
7
by: Alex | last post by:
Hi all, I am trying to install a java stored procedure via the windows development centre. The linux box is running 8.1 FP4 as is the windoze platform. If I am on the linux box i can install...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
4
by: Pakna | last post by:
Hi, is there any way to call a JAVA stored procedure from a SQL Trigger? We are having difficulties with this and cannot verify whether DB2 even *has* this capability? Thank you very much....
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
1
by: amgupta8 | last post by:
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2. Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.