Web service for returning a unique automatically incremented person identification number

I'm looking to create a simple web service that returns a unique identifier when polled. The identifier must be human readable (i.e. not oriented, probably in the form of 000023) and simply increases by 1 each time it is called.

Now I need to consider that it can be called by two different applications at the same time, and I do not want it to return the same number to each application.

Is there any other option than using a database to store the current number?

Of course, this was done earlier, can anyone point me to some source code, if any.

Thanks,

Neil

+5
source share
2 answers

Use a critical piece of code to control the flow of one piece of code. You can do this using a statement lockor a little more hardcore and using the mutex directly. Doing this ensures that you return a different number to each caller.

, , - SQLServer Oracle (, , , ), , -, , , ( ). , , , , .

- , , , .

+1

.

:

if (!locked('counter.txt'))
   counter = read('counter.txt')
else
   wait
   startAgain
lock('counter.txt')
counter++
print counter
write('counter.txt', counter)
unlock('counter.txt)
0

All Articles