Limit multiple simultaneous access to part of PL SQL code

Is there any provision in PL-SQL block by which some part of the PL SQL code can be restricted to be accessed by only one user at a time. Multiple request on the same part of the code will form a queue and will be executed one after the other.
I am working on an application that generates unique number for each request from the database by performing MAX+1. In multiuser environment, same number is assigned to all the user requesting number from the same table. We have observed duplicate value error generated due to simultaneous click for generation of number and both getting the same number and being inserted in the column which is defined unique.
Also pls. provide me some feasible solution apart from limiting simultaneous access to part of the code that generates number and updates the database.

If the number is generated by sequence and by any chance that transaction is rolled back then that sequence number is lost. I want numbers without any missing numbers in the column. What about these sequence of events:
1). A user gets a MAX + 1 value.
2). Saves the record.
3). Another user gets the next MAX + 1 value.
4). Saves the record.
5). User #1 then wants to delete his record.
Then you have a gap in between that will never be filled up if you keep doing MAX + 1.
Is this gap acceptable?
Or that
1). Delete of a saved record is not allowed by your application to avoid gaps.
2). You have some extra logic (apart from MAX + 1 always), to re-assign these deleted slots to next person asking for the sequence.
None of the above two sound reasonable.
Even if you fill a previously deleted slot for the next sequence reauest, You will no longer will be able to order the records in the order they were created and a deleted slot could remain "free" for a extended period of time, during which you still have to deal with the gaps in your sequence generation logic.
Is it worth considering using the Oracle sequence object instead?
Someone might say, yes. What about you?

Similar Messages

  • Accessing Secured Web Services fromPL/SQL  Code.

    Hi ,
    This is an urgent requirement.We need to call a Web Sercured which is secured(That we need Authenticate using Digital Signatures).I don't how to call a Secured web service from PL/SQL code.with java it is possible.
    Can anyone help me in confoguring/Writing code to call web services with Digital Certificates.
    Regards,
    Ram

    In the XmlDigester class you would have to change the following 2 functions...
    public int Compare(Object x, Object y)
    XmlAttribute lhs = (XmlAttribute)x;
    XmlAttribute rhs = (XmlAttribute)y;
    string ls = lhs.NamespaceURI;
    string rs = rhs.NamespaceURI;
    if ((ls == rs) || (ls.Equals(rs) && ls != null && rs != null))
    ls = lhs.LocalName;
    rs = rhs.LocalName;
    if (ls == null)
    return -1;
    if (rs == null)
    return 1;
    byte[] larr = Encoding.UTF8.GetBytes(ls);
    byte[] rarr = Encoding.UTF8.GetBytes(rs);
    int len = Math.Min(larr.Length, rarr.Length);
    for (int i = 0; i < len; i++)
    int li = (int)(larr[i] & 0xFF);
    int ri = (int)(rarr[i] & 0xFF);
    int d = li - ri;
    if (d != 0)
    return d;
    return larr.Length - rarr.Length;
    private void Serialize(string s, Stream outStream)
    byte[] bytes = Encoding.UTF8.GetBytes(s);
    int len = bytes.Length;
    Serialize((byte)(len >> 8), outStream);
    Serialize((byte)(len), outStream);
    Serialize(bytes, outStream);
    That should do the trick.

  • Can multiple LabVIEW programs simultaneously access the same NI-DAQmx hardware?

    I am developing a test station system that, in essence, runs several
    seperate LabVIEW programs simultaneously on the same computer, each
    controlling a different set of I/O channels on one shared set of NI
    DAQ hardware (analog and digital I/O PCI boards with external signal
    conditioning).
    I have already gotten a system like this running almost flawlessly
    using LabVIEW 6.1, NI-DAQmx 7.1 with traditional channels, and older
    E-series DAQ hardware. So long as two programs do not try to write to
    the same output channel simultaneously, everything works exactly as
    expected--I can even read from the same (named) channel simultaneously
    from more than one program. The only issue I have had is that if
    one
    of the compiled applications is closed (not just stopped, but closed)
    while others are still running, Windows XP (SP1) will bluescreen on a
    driver error. This is undesireable, but acceptable (though if there's
    a fix/workaround, I'd love to hear it).
    I am now building a similar system using mostly the same software
    (with an upgrade to LabVIEW 7.1), and I've noticed that the new
    M-series DAQ hardware seems to offer much more bang for the buck than
    old E-series hardware and its kin.
    My question is this: It appears that I/O on M-series hardware must be
    performed with new mx channels, with traditional channels not being an
    option. I am therefore wondering if I will be able to do this kind of
    multiple simultaneous access with mx channels, or if I must purchase
    the classic hardware and use traditional channels for this somewhat
    unorthodox application.
    (Incidentally, the multiple simultaneous program thing is a
    requirement for this system, as it is the only clean way to run
    multiple
    identical copies of the same complete program that only
    operate on different I/O channels, and re-doing the program from
    scratch is not an option.)

    Dear Anonymous,
    Thank you for contacting National Instruments.
    To address your question, I don't know if multiple simultaneous access with mx channels is possible, but I do not see why it wouldn't be. The best way to find out would be to test it. I don't have your program or hardware, so I'm pointing you to some Compatibility VIs. These are VIs that look exactly like Traditional DAQ VIs except that underneath they call the DAQmx driver instead of the Traditional DAQ driver. If your device works when you substitute these Compatibility VIs in for the Traditional DAQ VIs, then you'll know the M Series boards will work for you.
    Here is the link for information about the Compatibility VIs:
    http://digital.ni.com/softlib.nsf/954feaeea92d90918625674b00658b
    83/9d67f671bcc6850586256e630059308b?OpenDocument
    Let me know if you have any further questions or if this does not resolve your issue.
    Thanks again and have a great day!
    Chad AE
    Applications Engineer - National Instruments

  • Can I have multiple computers accessing one iTunes library simultaneously?

    I've purchased a Lacie Network HD that I'm keeping all of my iTunes on. I've put an alias to the iTunes library from that drive in the music folders of the computers I want to access and update it. That all works well. The only problem is that both computers cannot have iTunes running at the same time. I get an error stating that the library is locked. It would appear that I can't have multiple computers accessing the library at the same time. Is there a work around for this aside from doing network sharing via iTunes? The reason I don't want to do that is that I want both computers to have access to the actual files if I'm using the various iLife apps that use iTunes.

    Scott
    The only problem is that both computers cannot have iTunes running at the same time. I get an error stating that the library is locked. It would appear that I can't have multiple computers accessing the library at the same time
    This is true. It's not a server app.
    The nearest thing would be a library file on each machine pointing to the same set of music files. However, you might have problems if both machines try to access a particulat track at the same time. Also, changes made on one machine would not be reflected in the other. So if you rip a CD on one, the files will also have to be 'imported' to the other.
    Regards
    TD

  • Why does the Error: 500 SC_INTERNAL_SERVER_ERROR appear when multiple users access my JSPs but does not occur when only one user accesses my JSPs?

    When multiple users run my JSP application, why do some users get an Error: 500 SC_INTERNAL_SERVER_ERROR for certain JSP pages with the error message No such file or directory. The JSP listed on the Error 500 page varies and is not always the same. When only one user runs my JSP application, the problem does not occur?
    The database connection is held when the user logs in or accesses certain parts of the JSP and then is immediately released. No connections to the database are held.
    We are using Solaris 8 with MU_6 plus recommended patches.
    Enterprise Ultra 250
    iAS 6 SP 3

    Is anything showing up in the KXS or KJS logs?
    It sounds like you might having some kind of thread safety issue with your code. Either that or your guess about running out of database connections.

  • Limit # of simultaneous logins?

    Is it possible (or even practical) to try to do this?
    My client wants *light* security on a series of pages, and
    would like to
    have two categories of passwords -
    1. A single user, i.e., no simultaneous logins.
    2. A group user, i.e., multiple simultaneous logins, up to
    but not beyond,
    some ceiling.
    With PHP/MySQL is this feasible?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================

    I can't speak for the PHP universe, but principles tend to
    translate so I'll
    take a shot anyway.
    In ASP, you've got session_onstart and session_onend in your
    global.asa
    file. Obviously, if the user does not log out and just closes
    the browser,
    the session will remain active until it times out, but
    session_onend will
    run regardless of how the session is ended. The
    session_onstart and
    session_onend can be used to edit application variables
    (which are truly
    global and only fall out of scope when IIS is restarted). The
    application
    variable might, for instance, be named after the user ID and
    contain the
    number of current active sessions. Session_onstart is set to
    create or
    increment; session_onend is used to decrement.
    In the case of a user closing the browser, you'd have a login
    unavailable
    until the session timeout is reached. Typically, explaining
    this to users
    is good enough and everyone understands that if they make a
    mistake (or have
    the computer crash or something), they may need to wait 20
    minutes before
    they're allowed to log in again (assuming you're using the
    default 20 minute
    timeout). As long as it's known up front and not a nasty
    surprise, people
    are generally understanding.
    I don't think PHP has application variables, but you could do
    the same with
    a text file or a database table (with the bonus that a
    database table can be
    used to store session ID, login, logout, etc and give you all
    kids of
    history info). The crux of the matter is finding out if a PHP
    application
    has the equivalent of a global.asa and/or session_onstart and
    session_onend
    event handlers that are handled by the web server and not any
    particular web
    page. Sorry I can't be of more help there.
    "Murray *ACE*" <[email protected]> wrote
    in message
    news:[email protected]...
    > That was exactly what I told her.
    >
    > So - how would you approach this problem, then? One
    solution is to
    > monitor simultaneous logins, and that clearly is
    impractical.
    >
    > How would you enable 'group' access if not this way?
    >
    > --
    > Murray --- ICQ 71997575
    > Adobe Community Expert
    > (If you *MUST* email me, don't LAUGH when you do so!)
    > ==================
    >
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    > ==================
    >
    >
    > "Gary White" <[email protected]> wrote in
    message
    > news:[email protected]...
    >> On Thu, 6 Sep 2007 10:38:10 -0400, "Murray *ACE*"
    >> <[email protected]> wrote:
    >>
    >>>With PHP/MySQL is this feasible?
    >>
    >>
    >> Not really. Because some users may simply close the
    browser instead of
    >> logging out, you have no reliable method to
    determine who or how many
    >> may still be logged in.
    >>
    >> Gary
    >
    >

  • ARCA Xtra  - multiple user access to SQLite DB

    Hi Guys,
    I have having trouble with multiple users accessing a SQLite DB file from a projector. They can all open and browse the data through the projector fine, but if USER1 makes a change and clicks save, and then USER2 tries access the DB it causes USER2 to get a script error.
    Is it possible to write a script which tells the user that the DB is being modified so please wait, rather than throwing them out of the projector with a script error
    Thankyou

    If you want multiple users to access a database then you would probably be better off using one designed for that purpose like MySQL.
    But, if you are set on SQLite and if you can have multiple simultaneous connections which you seem to imply you can, then the best solution I can think of is to create a Class/Script that handles all the details of polling the database for availability and handles other issues like a progress dialogue box.
    You have to treat the database as an asynchronous action - meaning you send it a query and at some latter time it sends a result back via a callback. Doing it this way greatly simplifies any database queries you want to make. As long as your queries are fairly simple like SELECT, INSERT, DELETE, etc. then the code is fairly straight forward.
    Off the top of my head I wrote something to get you started. I have not tested this code but it does compile. The following is a Parent script that you would use to interface to your database in an asynchronous manner.
    -- Asynchronus SQLite
    property  pDB  -- instance of Arca xtra
    property  pTimeoutTime  -- how long in milliseconds to ping database
    property  pPingTime  -- time between database pings.
    property  RunningQuery  -- Boolean. is a query running? true/false
    property  pTimeOb  -- timout object for polling the database
    property  pCurOperation  -- set of data for current query
    property  pPingCount  -- how many times the current query has pinged the database
    property  pAlertBox  -- a MIAW, LDM, or a Sprite that informs the user as to the progress of the query.
    on new me
      arcaregister([0000,000,0000])
      pDB = xtra("arca").new()
      Result = pDB.openDB(the moviepath & "ST_data")
      if Result.errorMsg then
        alert("Error Opening Database" & return & pDB.explainError(Result.errorMsg))
        return void
      end if
      pTimeoutTime  = 10000 
      pPingTime  = 250
      RunningQuery = false
      pAlertBox = Sprite(1000)  -- for example
      return me
    end new
    on cleanup me
      pDB.closeDB()
    end cleanup
    on executeSQL me, Query, CallbackOb, CallbackMethod, OptionalParameters
      if RunningQuery then exit -- only allow one query at a time
      RunningQuery = True
      pCurOperation = [#Query:Query, #OptionalParameters:OptionalParameters, #CallbackOb:CallbackOb, #CallbackMethod:CallbackMethod]
      pPingCount = 0
      pTimeOb = timeout().new("QueryProcessor_"&me, 1, me, #processQuery)  -- creating the timeout object here breaks the call stack, which is good.
    end executeSQL
    on processQuery me, TimeOb
      Result = pDB.executeSQL(pCurOperation.Query, pCurOperation.OptionalParameters)
      if Result.errorMsg then
        if Result.errorMsg = 5 then -- database is currently locked
          pPingCount = pPingCount + 1
          if pPingCount = 1 then  -- then inform user there will be a delay.
            pAlertBox.setMessage("Waiting for database response.")
            pAlertBox.setProgress(0)
            pAlertBox.show()
            pTimeOb.period = pPingTime
            exit
          end if
          pAlertBox.setProgress((pPingCount * pPingTime / pTimeoutTime) * 100 ) 
          if pPingCount * pPingTime = pTimeoutTime then -- timed out
            alert("Query Timed out.")
          else
            exit  -- try again in pPingTime time.
          end if
        else  -- there is some sort of database error
          alert("Database Error: " & return & pDB.explainError(Result.errorMsg))
        end if
      else  -- no query errors
        call(pCurOperation.CallbackMethod, pCurOperation.CallbackOb, Result)
      end if
      -- if the code makes it this far then we are done and need to clean things up
      if pTimeOb. objectP then
        pTimeOb.forget()
        pTimeOb = void
      end if
      pAlertBox.hide()
      RunningQuery = false
    end processQuery
    on setTimeOutTime me, MilliSecs
      pTimeoutTime = MilliSecs
    end setTimeOutTime
    on setPingTime me, MilliSecs
      pPingTime  = MilliSecs
    end setPingTime
    You then create an instance of this script on preparemovie.
    -- Movie script
    global gDB
    on prepareMovie
      gDB = script("Asynchronus SQLite").new()
      if gDB.voidP then halt -- can not connect to the database
    end
    on stopMovie
      gDB.cleanup()
    end
    Then it is simply a matter of sending your queries to the gDB object and it will send the results back to the callback handler and object that you specify. Here's a behavior that shows how simple this should be:
    -- Sample DB Behavior
    global gDB
    on mouseUp me
      Query = "select * from users"
      gDB.executeSQL(Query, me, #setQueryResult) -- string, callback object, callback handler name
    end
    on setQueryResult me, Result  -- this is the callback handler/method
      put Result
    end
    I also suggest using a MIAW or a LDM or a set of sprites as a way to inform the user of any delays in processing a query. Check the code for pAlertBox to see how I use this idea to update a progress bar. Of course you will have to create the implementation.

  • Cannot establish multiple simultaneous PPTP connections with the CISCO 1841.

    Hello everyone;
    I have recently tested a PPTP connection with a CISCO 1841 router and got success. I have configured a windows 7 client and successfully connected to the router and was able to access the documents in the server PC that I have mentioned in the attached diagram. I have created number of different users  in the CISCO 1841 too. While some one is having a connection, another user cannot connect to it, which means multiple simultaneous connections aren't possible. Do I have to create a ACL for the PPTP and if yes, How ? 
     FastEthernet0/0 is up, line protocol is up
      Internet address is 192.168.100.1/25
      Broadcast address is 255.255.255.255
      Address determined by non-volatile memory
      MTU is 1500 bytes
      Helper address is not set
      Directed broadcast forwarding is disabled
      Outgoing access list is not set
      Inbound  access list is 100
    Proxy ARP is enabled
    Local Proxy ARP is disabled
    Security level is default
    Split horizon is enabled
    ICMP redirects are always sent
    ICMP unreachables are always sent
    ICMP mask replies are never sent
    IP fast switching is enabled
    IP fast switching on the same interface is disabled
    IP Flow switching is disabled
    IP CEF switching is enabled
    IP CEF Feature Fast switching turbo vector
    IP multicast fast switching is enabled
    IP multicast distributed fast switching is disabled
    IP route-cache flags are Fast, CEF
    Router Discovery is disabled
    IP output packet accounting is disabled
    IP access violation accounting is disabled
    TCP/IP header compression is disabled
    RTP/IP header compression is disabled
    Policy routing is disabled
    Network address translation is enabled, interface in domain inside
    BGP Policy Mapping is disabled
    WCCP Redirect outbound is disabled
    WCCP Redirect inbound is disabled
    WCCP Redirect exclude is disabled
    Inbound inspection rule is SDM_LOW
    --------------------------------------------------------------------------------------------ACL 100-----------------------------
    deny icmp any any echo-reply
    deny ip host 255.255.255.255 any
    deny ip 127.0.0.0 0.255.255.255 any
    deny ip host 66.163.169.186 any
    permit ip any any (122467027 matches)

    As long as you have the inspection engine enabled on the ASA, it shouldn't freak out of the different IP as it will inspect the call signalling and will NAT it accordingly, BUT, for simplicity, I agree with you, it would cause a lot of troubleshooting headache if there is problem as well as reconfiguration of IP on the host ends.
    Here is the NAT FYI:
    object network obj-10.10.96.0
       subnet 10.10.96.0 255.255.255.0
    object network obj-192.168.96.0
       subnet 192.168.96.0 255.255.255.0
    object network obj-10.10.14.0
       subnet 10.10.14.0 255.255.255.0
    object network obj-10.1.0.0
       subnet 10.1.0.0 255.255.255.0
    object network obj-192.168.1.0
       subnet 192.168.1.0 255.255.255.0
    object network obj-10.10.11.0
       subnet 10.10.11.0 255.255.255.0
    object network obj-192.168.11.0
       subnet 192.168.11.0 255.255.255.0
    nat (inside,outside) source static obj-10.10.96.0 obj-192.168.96.0 destination static obj-10.10.14.0 obj-10.10.14.0
    nat (inside,outside) source static obj-10.1.0.0 obj-192.168.1.0 destination static obj-10.10.14.0 obj-10.10.14.0
    nat (inside,outside) source static obj-10.10.11.0 obj-192.168.11.0 destination static obj-10.10.14.0 obj-10.10.14.0

  • Multiple User access in ATP

    I am designing custom ATP for our client. Actually, this logic accesses batch classification data and the calculation logic also differs.
    The concern that I have is if one user (say A) creates a sales order item and runs a successful Availability check and goes on to create second sales order item. simultaneously if another user (say B) comes to create new sales order item for same material. now the ATP quantity that second user gets should be less than the quantity confirmed by user A. But both the sales order have not been saved. so how do I block the quantities confirmed by A but yet not saved.
    Is there any special method for multiple user access at runtime.

    Thanks for ur reply. it was really helpful to gain more insights in my issue.
    1. For performance-related reasons, the only time when it makes sense to set the material block with quantity transfer is when it is common for several users to work on the same material simultaneously. And in VA01 there are many parallel Sales order creation
    2.You create a sales order for a material. During the availability check, this material is blocked. After the availability check is completed, the block is removed. The quantity reserved for this transaction is recorded in the blocking table. This information can be assessed by all others who are working with this material. If you save the order, the blocked entries are cancelled. this how Material block with quantity transfer in SD works.
    The concern that I have now is how to get Blocking Tables for transaction VA01.

  • Multiple Simultaneous Libraries

    I know people have library managers, and there are smart lists, but is there a way to have multiple simultaneous libraries (same thing for iPhoto is desired). Again, I want multiple libraries to be loaded at the same time, not a smart list or something that I have to stop and start iTunes to get access to. If not, perhaps a feature request to the iTunes developers. Just one case is for our mp3's we keep for use in our auto cd player, we want a library for just the mp3's to make it easy to cut mp3 cd's... someday they'll support the AAC format. Again this is just one case... I have other reasons for separating the libraries.
    Thanks
    Macbook Pro 17   Mac OS X (10.4.7)  

    Developers don't (officially) read these discussions.
    Why not send your request to http://www.apple.com/feedback/itunesapp.html.
    At least they will read it now.
    M

  • Excel web access web part Refresh

    Dear All,
    Please let me adress my SharePoint issues to you.
    Current situation:
    I currently have an excel file stored in one of my sharepoint libraries.
    The excel file has two tabs.
    The first tab contains data exported from a sharepoint list (with data connection)
    The second tab has a customized table based on the first tab.
    I created a page and added a Excel Web Access web part. The above mentioned excel file (tab2) is viewed in this web part.
    Problem:
    Everytime I change something in my sharepoint list, the changes will not be viewed in the web part. The changes will only view when I open the excel file in the library first, and then save it.
    Question:
    Is there a way I can refresh the data automatically, or manually without having to leave the page of the web part?
    If anyone has a solution please let me know, thank you for your help!
    Bob

    you can configure automatic data refresh.  fairly simple.  this article is for SQL data source, but the same process applies across the board.
    http://technet.microsoft.com/en-us/library/hh525341(v=office.15).aspx
    Christopher Webb | MCM: SharePoint 2010 | MCSM: SharePoint Charter | MCT | http://christophermichaelwebb.com

  • How to access Excel PROTECTED spreadsheet in SharePoint Web Access Web Part in SharePoint2013?

    I have excel file which is protected by password. I need to access Sheet 1 on SharePoint Web Part Page on Dashboard. While I add protected I can not able to Excel Sheet is corrupted as per below image.!
    While I add simple Excel Spreadsheet, it works properly. Is there any alternate solution to display excel spreadsheet on Web Page using Excel Services.

    Hi,
    Please try to remove protection from a worksheet to solve this issue.
    The following articles for your reference:
    Remove protection from a worksheet
    http://office.microsoft.com/en-001/excel-help/password-protect-worksheet-or-workbook-elements-HP010342808.aspx#BMunprotectsheet
    SharePoint 2013: Excel web access web part Errors and Resolutions
    http://amolmeshe.blogspot.kr/2013_06_01_archive.html
    How to Unprotect an excel sheet without password
    https://uknowit.uwgb.edu/page.php?id=28850
    We can also customize a web part to show the excel sheet.
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Excel Web Access Web Part on O365 SharePoint...

    Excel Web Access Web Part on O365 SharePoint seems to run VERY slow on excel oData SharePoint list query/refresh.
    Is there anything that can be done to speed this? Thanks

    Hi Alan,
    O365 SharePoint is hosted on the Microsoft cloud, we cannot check what may cause Excel oData query/refresh very slow, I would recommend you post this issue in our dedicated O365 forum for a better assistance. If the issue is related to O365 SharePoint
    server side, there may involve
    O365 back end support engineer to look into this issue.
    http://community.office365.com/en-us/f/154.aspx
    Thanks,
    Daniel Yang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Daniel Yang
    TechNet Community Support

  • Multiple users access one iPhoto library and view and edit

    I have 3 Macs and 5 users in our family. I'd like to have one iPhoto library that any user can access from any of the machines and view and/or edit. I don't need simultaneous access (which from reading posts I can see is not possible in iPhoto).
    If I move the library to external HD will I be able to access the libary from each Mac over Wi-Fi? From what I read I'd need to hold ALT when opening iPhoto in each user account, on each Mac, and choose the library on the external drive.
    If I set it up like this then once photos imported any user can see them, and edit if they want to? Presumably any Projects would be in the one central library rather tan being specific to a particular user?

    Yes and no
    the hard drive that the iPhoto sits on must be formatted Mac OS extended (jorunaled)
    iPhoto is not a multi user program and if two different people edit atthe same time it will not wrok correctly
    Most importantly WiFi is not a reliable connection and has many dropouts - if you edit over WiFi you are highly likely to lose data and corrupt yoru library - it is not a good idea - viewing is slow but will work
    LN

  • Multiple threads access the same method.

    Hello,
    I have been trying for a long time to find out multiple threads access the shared data.
    I have written a sample code, there I my intention is that method has to be accessed
    onlny one thread at a time., mean one thread finished the job, then next thread can
    access the shared source. But for this code I am not getting the desired out put what I want. But if I am using synchronized block I am getting the output. Please correct where I got mistake. Please see my code.
    public class TestThread implements Runnable {
         Shared r;
         public TestThread() {
              r = new Shared();
         public static void main(String args[]) {
              Thread t1 = new Thread(new TestThread());
              Thread t2 = new Thread(new TestThread());
              t1.setName("A");
              t2.setName("B");
              t1.start();
              t2.start();
          * (non-Javadoc)
          * @see java.lang.Runnable#run()
         @Override
         public void run() {
              // TODO Auto-generated method stub
              r.count();
    class Shared {
         public synchronized void count() {
              String name = Thread.currentThread().getName();
              System.out.println(name + ":accessed...");
              try {
                   for (int i = 0; i < 5; i++) {
                        System.out.println(name + ": " + i);
              } catch (Exception e) {
                   // TODO: handle exception
    }Thanks
    Bhanu lakshmi.

    It depends on what you synchronize. Non-static methods synchronize on the object, so if you're using several objects, you'll be able to call each from their own thread.
    Make your method synchronized or use only a single object and see the difference.

Maybe you are looking for