Best way to generate an incrementing ID in multithreaded environment

Hi
I have a "best practice" kind of question.
I need to insert a record in an Oracle table where primary key is an incrementing numeric ID. In order to insert a new record, first i need to figure out what the maximum ID is and then increment it.
In a multithreaded environment, this can cause an error when, let's say, there are 2 threads, and each one is simultaneously querying the table for the max ID. Each query will return the same result and hence only 1 query will succeed at inserting the new record. The second insert will cause a primary key conflict when trying to execute.
Is making the code synchronized the best solution in this situation or is there a better way?
Thanks in advance.

Hi,
using Oracle sequence could be easy and effective, just insert sequence.NEXTVAL into the particular column. Oracle should take care of possible conflicts, it should always provide different (means incremented) value.
I dont recommend using agregate function MAX(column).
Good luck,
Rgds
Miroslav

Similar Messages

  • Best way to generate ER diagram

    We have Oracle 11g in our environment. I wanted to know which should be the best way to generate an ER diagram. Below are these steps in SQL developer (version of SQL developer is 3.2.x):
    a) View → Data Modeler → Browser
    b) In browser tab, select show on newly created relational model
    c) Then just drag the tables you want (from e.g. the «Connections» tab) onto the model.
    The problem is I am not able to drag the tables.
    I hope I have been able to explain my requirement of generating ER diagram.
    Please revert with the reply to my query.
    Regards

    2) If all the tables are required in ER diagram, then should all the tables be selected in point c) of my post.
    If all the Tables in your relational diagram are to included in the ER diagram, just click the Engineer button.
    If some are to be excluded, you can expand the Tables node in the tree in the top part of the dialogue and deselect the ones you don't want.  Then click the Engineer button.
    1) How to save the ER diagram
    To save your model for future update, you can go to the File menu and select Data Modeler > Save.
    To save your diagram as a PDF or image file, go to the File menu and select Data Modeler > Print Diagram.
    David

  • Best way to implement auto increment in JPA.

    What is the best way to implement auto increment in JPA so that it will support all databases such as MySQL, MSSQL Server, Oracle etc. ? Or is there any way to set auto increment strategy in common place such as persistence.xml? Please help...

    All JPA strategies require something (like a table or sequence object) be in the database, with table sequencing being the most portable, though EclipseLink does allow custom sequence stratgies where you could use something else, such as the UUID. Sequencing is described here described here http://wiki.eclipse.org/EclipseLink/Examples/JPA/PrimaryKey with a custom UUID example shown here http://wiki.eclipse.org/EclipseLink/Examples/JPA/CustomSequencing .

  • Best way to generate dynamic html in apex

    Hi all,
    I have to create a complex page in html with tables within tables, ajax and a very large number of items (text fields).
    Like to have your opinion to know what the best solution to create this page. The HTML within the PL / SQL makes it difficult to manage in future. There is another way to generate HTML code, without being inside of PL / SQL?

    Hi 819517,
    You should be able to get your desired effect using regions and sub regions.
    As you can create your own custom templates for both.
    You may find issues with more than 50 fields on your form.
    You can get round this by re using field names (as in a multi row form).
    If you are submitting more than a few hundred fields, you may need to look at the settings for modplsql in apache (if you are using it) as the maximum number of form fields is a setting in the conf file.
    Regards
    Michael

  • Best way to generate one record per day from a table with eff/exp dates

    Hi,
    Have a table which has various attributes and an eff and exp date. e.g attributea, 01/05/2012, 16/05/2012
    We wish to create another table from this table to have one record per day. e.g 16 records.
    What is best way to achieve this in OWB ?
    Thanks

    Hi,
    Example if have table
    with following contents
    conversion_rate number(6,4)
    EFFEcTIVE_DATE DATE
    expiration_date date
    example record 1.43, 01/05/2012,16/05/2012
    If want to have another table which instead has 16 records one for each day
    e.g
    1.43, 01/05/2012
    1.43,02/05/2012
    1.43,16/05/2012
    Thoughts on best way to do this.
    Thanks

  • Best Practice to generate UUIDs in a Cluster-Server Environment

    Hi all,
    I just need some inputs over the best practices to generate UUIDs in typical internet world where there are multiple servers/JVMs involved for load balancing or traffic distribution etc. I know JAVA is shipped with very efficient UUID generator API.
    But still that doesn't solve the issue in multiple server environment.
    For the discussion sake lets assume I need it to be unique over the setup than a near unique.
    How do you guys approach it?
    Thanks you all in advance.

    codeNombre wrote:
    jverd wrote:
    codeNombre wrote:
    Thanks jverd,
    So adding to the theory of "distinguishing all possible servers" in addition to UUID over each server would be the way to go.If you're unreasonably paranoid, sure.I think its a common problem and there is a big number of folks who might still be bugged about the "relative uniqueness" of UUID in long run. People who don't understand probability and scale, sure.
    Again coming back to my original problem in an "internet world", shouldn't the requirement like unique id between different servers be dealt with generating the UUID's at a layer before entering into the multi-server setup. Where would that be? I don't have the answer..Again, that is the POINT of the UUID class--so that you can generate as many IDs as you want and still be confident that nobody anywhere is in the world has ever generated any of those same IDs. However, if your requirements say UUID is not good enough, then you need to define what is, and that means having a lot of foresight as to how this system will evolve and how long it will live, AND having total control over some aspect of your servers, AND having a process that is so good that it's LESS LIKELY for a human to screw up and re-use a "unique" server ID than the probabilities I presented in my previous post.

  • Best way to manage digital signing on Active Directory environment?

    Hi,
    I have created a couple of interactive documents and they have signature fields for the staff. Some documents have multiple signature fields. At the moment staff signing the document and emailing his/her supervisor and supervisor saving as this document and signing and forwarding to the principal. This is so messy and I was wondering whats the best way to create a usefull environment for it. Other very importing thing is how can make signatures centralized to prevent many signature creation on different computers?
    regards

    Hi,
    I am not sure if this helps for the second question, but...
    I use a single digital signature from GlobalSign and they do offer a centralised certificate management system from 5 digital signatures up. See here: http://www.globalsign.com/ssl/managed-ssl/.
    I haven't used it as I only have a single signature, but it may help.
    Niall

  • Best way to achieve PHD-like ability in home environment?

    We have 4 Macs at home.   Each mac (except mine) has 4 identical logons -- one for each member of the family.   The physical Mac themselves become just generic devices -- i.e. grab whichever one is available.    The problem arises when Kid 1 writes a term paper on Mac 1, later picks up Mac 2 and tries to edit it.   She then needs to find Mac 1 and log into her account....
    I read about OSX Server and thought about buying a Mini, turn on PHD, and have home directories sync'd in the background/logon/logout so that it truly doesn't matter which Mac a family member picks up.    Thought also about having a shared PHD for things likely to be accessed by multiple family members at the same time -- pictures, music, etc...
    Q:  Is OSX Server the best way to achieve this?   
    Q:  OSX Server on a dedicated Mini or just on my Macbook (which has tons of storage, the shared family stuff is there now anyway)?
    Q:  I've seen mention that two people can't simulataneously connect to the same PHD.  Is that true?   Would that make PHD unsuitable for a group shared file area?
    Many thanks in advance,
    Marty

    OS X Server can do this.  You'll need to set up local DNS, local shares and the rest, and then bind the client Mac systems to the Open Directory server.
    A Network Attached Storage device — or accessing a share that's been configured on whatever Mac was used, technically there's no need for server to export shares from Mac systems — is another and potentially much simpler option here.  Put the shared files there, and any Mac can access them.
    With Open Directory, folks would have their own logins, and I'd generally not look to have multiple logins in parallel with portable home directories in use.  Portable home directories are useful when the Mac systems are portable and leaving the local network on occasion.  If the Mac systems are not leaving the local network, then a network home directory is probably better.

  • Best way to generate the XML files from a DTD file

    Hey,
    I am writing an application that needs to convert a complicated data structure into an xml file. I have design a DTD file that describes the data structure.
    My question is what is the best, most efficient way to covert the data structures (objects) into the XML files with a DTD file.
    Thank you very much.
    Candy

    Convert the DTd to an XML Schema. Generate java classes from Schema with Jaxb. Create an XML document from the java classes.

  • Best way to generate report on huge data table

    Hi,
    I am using Oracle11g.
    I want to generate reports on transaction tables containing huge amount of data, on which very frequently DMLs are performing in real time.
    i want to keep my report/result in RESULT_CACHE for 15 mins. active. whenever any insert/update runs on main tables the RESULT_CACHE is getting invalidated
    my question is can i control/stop RESULT_CACHE relies on(table_name) invalidating, as Oracle11g invalidating RESULT_CACHE automatically.
    my requirement is to not hit the main table again&again.
    pls help..
    Thanks in advance.
    Vinod

    910575 wrote:
    Hi,
    I am using Oracle11g.
    I want to generate reports on transaction tables containing huge amount of data, on which very frequently DMLs are performing in real time.
    i want to keep my report/result in RESULT_CACHE for 15 mins. active. whenever any insert/update runs on main tables the RESULT_CACHE is getting invalidated
    my question is can i control/stop RESULT_CACHE relies on(table_name) invalidating, as Oracle11g invalidating RESULT_CACHE automatically.
    my requirement is to not hit the main table again&again.
    pls help..
    It sounds as if you're trying to avoid contention on a very busy large table while users are experimenting with relatively small fractions of the total data set. The type of thing you're doing is probably about the best approach - though it sounds as if you are not using global temporary tables which could save you a bit of time and contention when refreshing each private data set.
    Ideally, though, you probably want a front end tool that does client-side caching - i.e. pulls the data into the front-end tool and lets the user rearrange it cosmetically there until the user explicitly requests a new trip to the database. I think Oracle Discoverer has (had) some capability in this area. What's the scale of the work the users are doing - can you give us a few scenarios about how much raw data they will extract and what they want to do with it before they refresh it ?
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>
    P.S. Oracle does have client-side caching technology - but your ability to use it is dependent on the tools you use. You might want to go over to one of the developer or BI forums to see what they say about this problem; they may give you a different perspective on it.
    Edited by: Jonathan Lewis on Jan 31, 2012 6:55 PM

  • What is the best way to generate a "boot.log" on an arch64 system?

    I want to save the information echoed to the screen during boot to a log file.
    My understanding is that this can be enabled in several ways, but usually most cleanly by appropriately modifying one's syslog.conf file.
    Looking inside "/etc/syslog-ng.conf" it's not clear that the boot.log functionality is in fact easily turned on with arch systems. 
    For old redhat systems (eg.) this information used to be routed through "local7."  Does anyone know the proper (or at least a good) way to do this on a modern arch system?  I'd like to avoid an ugly hack.

    I want to save the information echoed to the screen during boot to a log file.
    My understanding is that this can be enabled in several ways, but usually most cleanly by appropriately modifying one's syslog.conf file.
    Looking inside "/etc/syslog-ng.conf" it's not clear that the boot.log functionality is in fact easily turned on with arch systems. 
    For old redhat systems (eg.) this information used to be routed through "local7."  Does anyone know the proper (or at least a good) way to do this on a modern arch system?  I'd like to avoid an ugly hack.

  • What's the best way to generate a dashed outline in Photoshop?

    For example, what you'd find around a coupon in a newspaper.
    Thanks!

    Sorry, I was pretty terse.
    But you will need to understand how paths work, how you can run a brush stroke along a path, and how to set up a brush to do what I said.
    Perhaps this will help get the brush set up:
    -Noel

  • Which one is the best way to generate an array of large waveform?

    The problem is that I have an array of 4 waveform of 2,8 millon of samples each one and when I put it in the buffer an error say me that there is not sufficient space.
    My computer is a PII MMX of 350MHz and 384MRAM. I`ll really appreciated that you people can help me.

    Use the initialize array function on the outside of a loop wired to the input of a shift register. If you can initialize the memory on the outside of the loop, it will reserve this range for use inside the loop.
    Attachments:
    initialize_array.gif ‏5 KB

  • Best way to create a similar 2 node RAC environment

    Hello all,
    I have a 2 node RAC(10.2.0.3) running on Solaris 10 as my Prod Database.
    We are planning to have another 2 node RAC for DEV purposes with 10.2.0.3 itself.
    [Due to certain reasons this will act as the PROD for few weeks, so we need exact copy of the DB]
    I cannot afford any downtime.
    i am planning to
    Install CRS and upgrade to 10.2.0.3
    Install RAC and upgrade to 10.2.0.3
    Duplicate the database using RMAN
    Are there any better ways that i could replicate the environment either using Grid Control(10.2.0.2) or Dataguard (or anyother) ?
    TIA,
    JJ

    I don't think you're going to achieve no downtime, but if you get the DB copied to the 2nd cluster (using RMAN or whatever method you like) and apply all the logs, then your downtime should be able to be limited to the time it takes to apply the last log or two once you shutdown the primary site (a la Data Guard). That should also allow you to avoid data loss by applying the last logs (you'll likely have to manually copy and apply them). I agree with DbaKerber that using Data Guard may not be a bad solution here. You're not going to get 0 downtime, but I think it would be the safest way to have the shortest downtime window with no data loss.

  • What is the best option for generating .wmv video working on Mac?

    I am working on a mac. I need to generate my output in .wmv. I am exporting as .mov then using MacX converter to convert to .wmv. The quality degrades too much. What is the best way to generate .wmv?
    Thanks in advance.

    YOur statement is way too generic and vague. You have not provided any exact settings,  version info, details about the footage etc. That asude WMV is a compressed format and wil always degrade.
    Mylenium

Maybe you are looking for

  • Error while running the tcode....EASISI

    hello Experts, I am trying to execute the tcode EASISI with a varient..... All the proper values are given to....... Simulation From,Simulate To,Document Date,Posting Date,Installation,Invoicing simulation,Simulate invoic. for ind. doc., and Billing

  • Two values in each node of a JTree

    How can i store two values in each treenode of a jtree? The first one is invisible and the second is the one displayed in the tree list.For example, i want to store the id of a database table in the invisible element and a display name in the second.

  • NIO - Selector problem - when using more than one in same application

    Hi, I'm developing a multiplayer-server, which shall be able to handle at least 2000 concurrent clients. To avoid the use of 4000 threads for 2000 clients (a thread for each stream), I would like to use NIO. Problem: The server has of course a Server

  • Need Help, Quicktime created a "dead end"

    Hello everyone. I need some help. I filmed some stuff with photo booth, and have a bunch of .movs. I threw them together and edited them using Quicktime Pro. I assembled them into a little video. I saved it and everything. Then I closed Quicktime, an

  • Apple TV 2 w/5.2 software.  AFTER ONE MINUTE IN PAUSE IT GOES BACK TO THE HOME SCREEN.

    I just updated my Apple TV Ser.2 to the 5.2 software.  Now, whenever I pause it it goes back to the ATV home screen after only about a minute.  To resume playing I have cursor down to Netflix, select the program and start playing it again.  Can I jus