By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.