In my application i have to give each user who logs into the appliation a unique transaction id. for this the requiremnt is to obtain the max value from a DB2 table, increment it and the insert it. The problem is that incase another user also logs in the sametime he/she has to be provided a unique id. to ensure his i feel that i would need to implement a table level lock. However this would make it highly ineficent i the case of heavy traffic and causing timeout for many users. Please suggest how should such a case be handled. I am using jdbc and backend is db2 v6.1...
I would write a method to generate a unique string identifier. First generate a large random number . Make sure it has a large range of output. Then use " ref = new StringBuffer(Long.toString(strNum))" to convert it and pass it to a StringBuffer object. Randomly insert a few chars into the string and use ref.toString() again before sending to your table. Or, if you wanted to make things a bit easier, use System.currentTimeMillis() to obtain a long which won't be duplicated unless System.currentTimeMillis() is called w/in the same millisecond. The first solution may seem like a hack but I have used this several times effectively especially with a lot of simultaneous traffic. It is possible to issue a duplicate w/ the first but if you write the method well it will be next to impossible. Hope this helps
"Shane", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please re-register and select a new name which meets the requirements. Thanks. On a personal note, its nice to see someone come out of the blocks answering questions rather than asking them, it's appreciated. Dave
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com