Locking multiple objectsat same time?

Hi All,
I have a design question for an LRU cache class. The class has a hashmap which acts as the cache and a linked list with the most recently accessed item at the head of the list. Both of them together help to maintain an LRU cache.
Now when I need to perform operations like add, update, remove items from the LRU cache, I need to add, update, delete from the cache as well as the linked list. So all my methods need to ensure thread-safe concurrency on 2 shared objects (hashmap and linked list) at same time, and not only on one shared object. How can I achieve this?
I do not plan to synchronize the methods, but I plan to synchronize on the shared objects. In method 1 if I synchronize on the hashmap, then any other thread can enter method 2 and can modify the linked list. If I I synchronize on linked list, then same problem will be there for hashmap. So how can I synchronize on both the objects at same time??
or should I synchronize on the 'this' object (object of LRU cache) itself? ( I do not want to do this)
or should i declare the methods to be synchronized? ( i do not want to do this)
Any comments will be highly appreciated.
Thanks.

Why do i feel that it is not possible...
So it means that if I have
LRUCache obj = new LRUCache();
then,
synchronized(obj){ /// }
and
synchronized(obj.obj1) {//}
are both possible by 2 different threads?
I know that obj and obj.obj1 are 2 different objects, but one is a part of another, isn't it? So it should not be possible?

Similar Messages

  • How to Add Album Art to Multiple Songs Same Time?

    I have many scenarios where 60-70 songs will share the same imported album art. Is there a method to add the art to the bulk of songs all at the same time. Similar to the multiple item entry field?
    Thanks!

    Is there a method to add the art to the bulk of songs all at the same time. Similar to the multiple item entry field?
    You do it exactlky the same.
    Select all teh songs you want, right click - get info.
    Tick the box next to Artwork and drag or paste artwork into the box.
    -> iTunes: How to add artwork to songs and videos in your library

  • How to run report from multiple user same time

    Hi,
    We are using oracle database 11g R2
    Oracle Forms & reports : 11.1.2
    O.S : Windows & Professional
    We have install oracle database, Oracle forms & reports in server. Near about 25 users are accessing that database, forms & reports from server through browser.
    I have one problem, when users runs a report there report goes in queue and runs one by one in FIFO manner.
    If one user has a report that take long time other users has to wait for that time.
    Can it is possible to run reports in multitasking manner, i.e multiple report can be run simultaneously.
    http://servername:7001/reports/rwservlet/showjobs?
    Using above url am able to see jobs in queue.
    Thanks in advance.

    Hi Denie,
    I am new to it and don't know how to add engines to server.conf , can you please tell me how to add engine to it.
    I search server.conf file but i did't found it.
    Please help..
    Thanks in advance.

  • HT4085 How can I disable the mute & disable the lock rotation at same time?

    I need to disable both the lock rotation & the mute from the side switch but I can't, I have to choose between one of them, how can I fix that?

    Use side switch to control Rotation
    http://i1224.photobucket.com/albums/ee374/Diavonex/5230822eb22c556c35a72a6589181 682.jpg
    http://i1224.photobucket.com/albums/ee374/Diavonex/6a787edc3564e00c2ca6b70d4f236 e8b.jpg
    Use Task Bar to control Sound (Mute)
    http://i1224.photobucket.com/albums/ee374/Diavonex/7b9878f2bec0242b7cf569af6b5df 1e3.jpg
    http://i1224.photobucket.com/albums/ee374/Diavonex/f1063310b398e24b3090698d5600e 96d.jpg
    Message was edited by: Diavonex

  • IPad 2 stuck in portrait, mute switch locks orientation and mutes at the same time.

    Ok, since I've had the iPad this problem has gone from bad to worse. Originally my iPad would get stuck in an orientation for random period of time and then unfreeze. Hours or days I would never know. If it was in landscape and I needed it in portrait I could just reboot and it would revert to portrait but not the other way around. It's been struck for 3 or 4 days now in portrait and now a new bugmhas appeared. Setting the hardware button to mute works fine, but still the software orientation button is useless. Only now, if I switch then hardware button to orientation lock, it tells me I'm muted and I'm orientation locked at the same time. And the software button works for the mute now. Need help. Thanks.

    In other words, can I have my screen rotate automatically as I hold my iPad in either portrait or landscape AND hear sounds from my apps at the same time?
    Yes, you can. You can configure the Side Switch (above the volume button) either as Mute switch or Rotation lock.
    Settings > General > Use Side Switch to: choose what you like the Side Switch to function as.

  • How to lock multiple user for a transcation code at same time is der any tc

    how to lock multiple user for a transcation code at same time is der any tc
    suppose i hav 15 user and i want to lock 10 user for mm02 who can i to it

    Basis can do a export and import transport, still if don't have connection between boxes.
    or
    check this
    http://www.sap-basis-abap.com/abap/copy-program-variants-from-one-to-another.htm

  • Updating single row by multiple users at the same time

    Hi,
    I have been asked to develop an application where a single row from a table will be accessed by multiple users. Even multiple users can try to update the same row at the same time. So, to provide a solution of this problem should it be the best way to lock that particular row when user requesting to update it and after completion of commit the lock will be released. In the same time if some other user request to update the same row then it will be in the wait condition.
    Please provide suggestion that is it the best way to handle the situation or not. If it is then can you also please provide an example (with sample code) of it.
    Regards,
    Koushik

    It depends entirely on how the system was built.
    You could relatively easily build an application that does something like
    - Select a row with as last_updated_date column
    - Update the row specifying the last_updated_date you had selected in your WHERE clause
    - If the update updates 1 row, it was successful, otherwise inform the user that the row was already updated.
    In this case, the second user would get an error indicating that the seat had already been purchased.
    You could also relatively easily do a SELECT FOR UPDATE to prevent users from ever getting an error between the time they select a seat and the time they finish their transaction. Of course, if the user wanders away from the computer, or inadvertently ends up locking dozens of rows, this tends to rather problematic in practice. You may find that when the train pulls out of the station, someone that never ended up buying a ticket has locked a dozen rows so you lost a dozen sales. If you have a call center where operators are reserving seats for people on the phone, you may decide that explicit locking is more appropriate because you're confident that the operators aren't going to leave tickets locked for long periods of time and the cost of having the customer walked through the seat selection process multiple times would be higher than the cost of having rows locked longer than they need to be.
    Justin

  • Prevent multiple users from updating coherence cache data at the same time

    Hi,
    I have a web application which have a huge amount of data instead of storing the data in Http Session are storing it in coherence. Now multiple groups of users can use or update the same data in coherence. There are 100's of groups with several thousand users in each group. How do I prevent multiple users from updating the cache data. Here is the scenario. User logs-in checks in coherence if the data there and gets it from coherence and displays it on the ui if not get it from backend i.e. mainframe systems and store it in coherence before displaying it on the screen. Now some other user at the same time can also perform the same function and if don't find the data in coherence can get it from backend and start saving it in coherence while the other user is also in the process of saving or updating. How do I prevent this in coherence. As have to use the same key when storing in coherence because the same data is shared across users and don't want to keep multiple copies of the same data. Is there something coherence provides out-of-the-box or what is best approach to handle this scenario.
    Thanks

    Hi,
    actually I believe, that if we are speaking about multiple users each with its own HttpSession, in case of two users accessing the same session attribute in their own session, the actually used cache keys will not be the same.
    On the other hand, this is probably not what you would really like, you would possibly like to share that data among sessions.
    You should probably consider using either read-through caching with the CacheLoader implementor doing the expensive data retrieval (if the data to be cached can be obtained outside of an HTTP container), or side caching with using Coherence locks or entry-processors for concurrency control on the data retrieval operations for the same key (take care of retries in this case).
    Best regards,
    Robert

  • CLR trigger - handling multiple inserts at the same time

    Hi
    I've developed a CLR trigger which operates on inserts performed on a staging table. The trigger implements some business logic and then inserts or updates a record in a target table. Whether an insert or update is performed depends on whether
    a record with the same ID already exists in the target (i.e. a select * from target where ID = 123).
    This works fine in most scenarios, but occasionally I am getting duplicates in the target table and have noticed that this seems to occur when inserts on the staging table happen at exactly the same time (i.e. multiple inserts for the same ID at
    the same time). In this situation duplicates are created in the target table because at the time of the inserts, no record with that ID exists in the target table (i.e. the select returns no records), therefore a new record is created for each.
    Is there a known way to deal with this scenario? For example, would locking the target table on insert result in the subsequent selects against the target table waiting until the target table had been updated, therefore the select would return a record
    for the given ID.
    I didn't really want to lock the whole target table on insert, because there are potentially other users reading that table (selects) and these would also have to wait for the insert to complete.
    I'd appreciate any thoughts on how to deal with this and avoid duplicates in the target table. I'm unable to change the way the data is coming in to the staging table, so my trigger code must deal with the above scenario.
    Thanks in advance.
    John

    First if you do not want any duplicate values in a column (or combination of columns) you should add a constraint to ensure this is never possible. A
    unique index
    like this should do this trick.
    CREATE UNIQUE NONCLUSTERED INDEX [IX_yourIndexName] ON [dbo].[YourTableName]
    [yourColumn1] ASC,
    -- add more columns that make the unique combination that you don't want repeated
    You can then add a try/catch block in your trigger code, if you get an exception based on this index then the record was created by another executing instance of this trigger and in that case you should do an update (or not, not sure what the rest of your
    logic is) in your catch block. This is the easiest solution and does not involve table locks. The only drawback is the first one to commit the insert will win and you have no guarantee which process or data set that will be. Also i have no idea how big the
    table is, how frequently changes are made, and what the data type is so you should
    keep this in mind when creating your index so you don't run into unexpected high index fragmentation which can lead to performance problems when executing updates and inserts.
    You could also create a
    named transaction with scope serializable around your insert/update block and execute your reads using a
    NOLOCK hint
    which should allow them to retrieve uncommitted writes and not create a long wait. The downside is is that the data might not be 100% accurate depending on if a transaction fails or not if there happens to be an update at the same time as a select but maybe
    this is not a big deal to the calling code.
    -Igor

  • Multiclips and multiple audio tracks playing at the same time

    I've only just taken delivery of my first ever mac (only ever used PC) with FCP, and I'm loving it already! Done lots of reading and viewing of video etc etc, and it's not as daunting as I thought it might be. I have one question the books don't seem to answer, and I can only find one reference to this on this site, with no definitive response. FCP5 probably doesn't work this way, but just in case someone knows different......
    I film and edit motorsport (karting) programmes for television in the UK, using multiple cameras. I usually lay all the video and audio tracks on the timeline, (synched) lock the audio for each (as it is engine noise, and I want it playing without abrupt changes at cuts as each kart passes each camera, whether in shot or not) then cut the video tracks and delete those video segments not required.
    The most exciting aspect of FCP5 for me is the multiclip editing facility, which I have found very easy to learn and is going to save me hours of work! However, I want to know if there is a way of having each audio track from each camera used in the multiclip laid down on the timeline when you import the multiclip to the timeline from the viewer, in order that I can play each audio track from each of the cameras at the same time.
    I know how to cut from angle to angle, leaving the audio from the selected angle as the one audio track playing, but I want all of the tracks to appear in the timeline and play at the same time. I know there's a bit of a workaround by locking the video and importing each audio track from each clip independently, but if you do have to re-synch one of the multiclips, this means the audio is not then synched with the original clip, which will have had an in point set before being imported in as part of a multiclip.
    I can understand why you might want to keep audio from one camera only playing over the whole multiclip, or to switch between audio from each, but in my case I prefer all audio to play at the same time. The workaround is still do-able for me as I'm only talking about engine notes, which if they are a few frames out is not very noticeable at all, but I would like to know if I'm right in thinking I cannot do it the way I would like to?
    Wish I'd used FCP from the start, but glad I've got it now.....especially with the 30 inch screen! It's 4.40am, been going over 19 hours straight and I'm still making comments like...."WOW, that's brilliant"...every half hour!
    G5   Mac OS X (10.4.3)   Quad, 8gb ram, 2 x G-Media GRaid 500gb Raids, 30 + 20 inch Cinema screens

    ...

  • Running multiple instances of program at same time problems

    I have a c++ program that uses BerkeleyDB 4.8.26 with transactions. Program works well, and I can run multiple instances of program and they cooperate on database very well. Problem arises when I run a small test program that runs 10 instances of the same program at same time.
    Test program opens database with transactions, it does some database reads and writes and quits. This test is run in 10 instances of the same program at the same time. Some instances run and finish well, other instances end up with some of these errors:
    unable to allocate memory for the lock table
    PANIC: Cannot allocate memory
    Error opening environment: DB_RUNRECOVERY: Fatal error, run database recovery
    another with:
    db_files/__db.001: No such file or directory
    db_files: No such file or directory
    Error opening environment: Invalid argument
    others with this one:
    Log file corrupt at LSN: [1][84474]
    fileops: close db_files/log.0000000001
    PANIC: Invalid argument
    unable to join the environment
    db_files: No such file or directory
    Error opening environment: DB_RUNRECOVERY: Fatal error, run database recovery
    I don't understand reason of this error, as I thought (and read) that BerkeleyDB should be able to handle multiple instances accessing database and is thread-safe.
    I tried to run the test on both NFS and local disk drive with same results.
    Is there anyone with ide what could be causing this problem ? My platform is x86_64 GNU/Linux 2.6.18-164.el5
    Edited by: Miro Janosik on 21.9.2010 22:42

    If there is someone who would like to look at this problem I'd like to show you program log files with verbose output turned on. There are 11 log files in the archive: http://bin.mypage.sk/FILES/log.rar
    Log files that end up with lines like this one below mean that program finished running ok:
    4000|0     4     20100922 07:07:24.094     20100922 07:07:24.094     FLOW_CMD
    Here below is output from one of log files:
    FilePersistentStorage::open() start
    FilePersistentStorage::open() ReadDir
    FilePersistentStorage::open() db_env_create
    FilePersistentStorage::open() db_env_create ok
    FilePersistentStorage::open() set cachesize
    FilePersistentStorage::open() set_tx_max
    FilePersistentStorage::open() set_timeout
    FilePersistentStorage::open() set_lk_detect
    FilePersistentStorage::open() exists homedir?
    envp->open
    FilePersistentStorage::open() envp->open
    fileops: stat /var/tmp
    fileops: open db_files/__db.rep.init
    fileops: close db_files/__db.rep.init
    fileops: open db_files/__db.001
    fileops: close db_files/__db.001
    fileops: open db_files/__db.001
    fileops: mmap db_files/__db.001
    fileops: close db_files/__db.001
    unable to join the environment
    fileops: directory list db_files
    fileops: unlink db_files/__db.005
    fileops: unlink db_files/__db.004
    fileops: unlink db_files/__db.003
    fileops: unlink db_files/__db.002
    fileops: unlink db_files/__db.001
    fileops: open db_files/__db.001
    fileops: open db_files/__db.001
    fileops: read db_files/log.0000000001: 12 bytes at offset 371
    Finding last valid log LSN: file: 1 offset 371
    fileops: close db_files/log.0000000001
    fileops: open db_files/__db.005
    fileops: seek db_files/__db.005 to 794624
    fileops: write db_files/__db.005: 8192 bytes
    fileops: mmap db_files/__db.005
    fileops: close db_files/__db.005
    fileops: open db_files/__db.006
    fileops: seek db_files/__db.006 to 376832
    fileops: write db_files/__db.006: 8192 bytes
    fileops: mmap db_files/__db.006
    fileops: close db_files/__db.006
    fileops: open db_files/log.0000000001
    fileops: read db_files/log.0000000001: 12 bytes at offset 335
    fileops: read db_files/log.0000000001: 371 bytes at offset 0
    fileops: directory list db_files
    fileops: open db_files/log.0000000001
    fileops: read db_files/log.0000000001: 28 bytes
    fileops: close db_files/log.0000000001
    Recovery starting from [1][243]
    fileops: close db_files/log.0000000001
    fileops: open db_files/log.0000000001
    fileops: read db_files/log.0000000001: 28 bytes
    fileops: write db_files/log.0000000001: 92 bytes at offset 371
    fileops: flush db_files/log.0000000001
    fileops: close db_files/log.0000000001
    fileops: open db_files/log.0000000002
    fileops: close db_files/log.0000000002
    fileops: open db_files/log.00002
    fileops: close db_files/log.00002
    fileops: open db_files/log.0000000001
    fileops: seek db_files/log.0000000001 to 463
    fileops: write db_files/log.0000000001: 4096 bytes
    fileops: write db_files/log.0000000001: 4096 bytes
    fileops: write db_files/log.0000000001: 4096 bytes
    fileops: write db_files/log.0000000001: 4096 bytes
    fileops: write db_files/log.0000000001: 3633 bytes
    fileops: close db_files/log.0000000001
    Recovery complete at Wed Sep 22 07:07:23 2010
    Maximum transaction ID 80000002 Recovery checkpoint [1][371]
    FilePersistentStorage::open() ok
    envp->lock_detect
    FilePersistentStorage::open() lock_detect
    rejected locks count: 0
    db_create
    dbp->open
    fileops: stat db_files/test_aaps.db
    fileops: stat db_files/test_aaps.db
    fileops: stat db_files/__db.80000001.d9f23b56
    fileops: open db_files/log.0000000001
    fileops: read db_files/log.0000000001: 28 bytes
    fileops: write db_files/log.0000000001: 67 bytes at offset 463
    fileops: flush db_files/log.0000000001
    fileops: open db_files/__db.80000001.d9f23b56
    fileops: stat db_files/__db.80000001.d9f23b56
    fileops: seek db_files/__db.80000001.d9f23b56 to 0
    fileops: write db_files/__db.80000001.d9f23b56: 4096 bytes
    fileops: seek db_files/__db.80000001.d9f23b56 to 4096
    fileops: write db_files/__db.80000001.d9f23b56: 4096 bytes
    fileops: flush db_files/__db.80000001.d9f23b56
    fileops: close db_files/__db.80000001.d9f23b56
    fileops: stat db_files/test_aaps.db
    fileops: stat db_files/__db.80000001.d9f23b56
    fileops: unlink db_files/__db.80000001.d9f23b56
    fileops: open db_files/log.0000000001
    fileops: read db_files/log.0000000001: 12 bytes at offset 463
    DB_LOGC->get: LSN 1/463: invalid log record header
    DB_TXN->abort: log undo failed for LSN: 1 463: Input/output error
    fileops: close db_files/log.0000000001
    PANIC: Input/output error
    fileops: open db_files/log.0000000001
    fileops: read db_files/log.0000000001: 12 bytes at offset 463
    PANIC: fatal region error detected; run recovery
    DB_LOGC->get: LSN: 1/463: read: DB_RUNRECOVERY: Fatal error, run database recovery
    DB_TXN->abort: log undo failed for LSN: 1 463: DB_RUNRECOVERY: Fatal error, run database recovery
    fileops: close db_files/log.0000000001
    PANIC: DB_RUNRECOVERY: Fatal error, run database recovery
    PANIC: DB_RUNRECOVERY: Fatal error, run database recovery
    dbp->open end
    dbp->close
    PANIC: fatal region error detected; run recovery
    envp->close
    File handles still open at environment close
    Open file handle: db_files/log.0000000001
    fileops: close db_files/log.0000000001
    PANIC: fatal region error detected; run recovery
    Database 'db_files//test_aaps.db' open failed: DB_RUNRECOVERY: Fatal error, run database recoveryDatabase close failed: DB_RUNRECOVERY: Fatal error, run database recovery
    environment close failed:

  • Running PSConfig on multiple servers at the same time

    Hi - we are updating an 8 server farm with a CU and in order to reduce downtime I am wondering whether it is supported/risky to run PSConfig on multiple SharePoint servers at the same time
    I plan to run the first one by itself - then after that set 7 off at the same time
    In the past I have always run them serially just to be cautious but there is pressure to reduce downtime so I want to know if there is any risk in running them simultaneously
    Thanks!
    J

    In general its not a good idea.  Running PSConfig will try to establish a lock on the configuration database.  Doing that from two servers at the same time may cause the update to fail.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Again, cannot start multiple domains at the same time

    Because the original question is marked as answered and the problem persists, I need to submit it again:
    With the latest plugin, in Glassfish Kepler, when I try to start the second server (same Glassfish, different domain) - it'll simply not start (the console remains empty) and after a while I get the time-out message, that the server could not be started. Even if 2 Eclipses are started, there only one server at a time can be started.
    This is a major issue for me, can you please help? Is there a lock file that I can delete or another workaround?

    Hi. The weird thing is that after the last update it worked for me, too, for a while - but then it didn't. I think there may be some sort of lock that hasn't been released when a forced shut down happened...?
    If I start the servers either outside of eclipse (command line), or using eclipse's external tools (which is pretty much the same, I think), they work just fine. And the status in the servers view gets updated to either started/stopped, correctly.
    And also, the case when I create domains/start servers outside of eclipse and then create the server in the servers view, the status update works.
    So yes, if there are multiple domains started at the same time outside of eclipse, the plugin shows them, but it cannot start them itself.
    Eclipse GlassFish Tools
    Part of Oracle Enterprise Pack for Eclipse 12.1.2.1 - version 6.2.0.201307232054
    Glassfish
    Installed Version: 
    Oracle GlassFish Server 3.1.2.2 (build 5)

  • How to play one clip multiple times at the same time?

    I am writing a little game where a certain sound has to be played quite frequently. I load it as a Clip and play it with
    myClip.setFramePosition(0);
    myClip.loop(0);If the sound has to be played again but is still being played by another event, the setFramePosition() method resets the sound and the first playing instance is cut off.
    A workaround would be that each object that needs to play this sound would get its own copy, but that is not feasible due to heavy memory consumption.
    So here it goes: How can I play a single sound multiple times at the same time? Is that possible?
    Edited by: andrasz on Feb 27, 2009 12:37 AM

    If the sound has to be played again but is still being played by another event, the setFramePosition() method resets the sound and the first playing instance is cut off.
    A workaround would be that each object that needs to play this sound would get its own copy, but that is not feasible due to heavy memory consumption.
    So here it goes: How can I play a single sound multiple times at the same time? Is that possible?Ummmm, if you're using a clip, you'll have to maintain one copy per object that needs to play the sound concurrently. You could keep one master copy, and then create copies of the clip as necessary to play them, and then just dump the copies to decrease memory consumption.
    A second idea would be to write your own Clip class. Esentially, all you would need to do is dump some sound data onto a TargetDataline to play it. It'll handle the buffering and playing at the correct speed itself. If that's all you did, you should be able to dump multiple times from the same instance and play it multiple times.
    Obviously, that's just a theory. In practice, it may not work that way...

  • How do you stop multiple users executing the same calc script at the same time?

    We have an issue when  users uplaod a spreadsheet and then run a calc script. at one time we have multiple exectuions of the script running.
    This slows up the system and we have to go cancel all the executions and run it again.
    Can we stop this and put them on a queue, so only one execution of the calc happens at one time. Or stop multiple executions getting submitted at all.

    You could use EXCLUSIVECALC to stop more than one calc running at the same time, although this will apply to all applications on your server.  And it doesn't just stop the same calc being launched twice.  Easier than the alternatives I can think of though, if it works for you.

Maybe you are looking for

  • Can't get jsp:plugin to work with jb5

    I am trying to get a Swing applet compiled with JDK 1.3.1 to run on a jsp page using the <jsp:plugin> tag. At this stage it is a ridiculously simple applet (just some JLabels and JTextFields) but I can't get it to work. Here is the jsp code: <jsp:plu

  • Warning that the library cannot be loaded because it is from a newer version of Aperture

    I'm getting a warning message that the library cannot be loaded because it is from a newer version of Aperture

  • Does Safari 5 come in 64 Bit Version?

    I know adobe flash doesn't support 64 bit browsers but I was just wondering if Apple even had a 64 Bit version of Safari available for Windows? Or is Safari only available in 32 Bit? What about Mac OSX?

  • Trouble Viewing PDF's in Safari

    When I click on a pdf to read it, I get a black screen and a message  that " ADobe Reader blocked for this website"  If I click on the message, it gives me a window that allows me to Trust the site and then will open the pdf.  It won't allow me to do

  • Importing remote classess and libraries

    Hi I'm new to java and have problem with importing packages that are not standard, for example: import com.<something here>; or import org.<blahblah>; and so on. I'm using netbeans and it points an error saying package does not exist. how to solve th