This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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