Modify, put and get : operations under transaction

Hello,
I use Coherence 3.0 with CONCUR_PESSIMISTIC.
When threads t1 and simultaneously t2 get the object obj1, they obtain it whitout waiting any lock. It's OK.
However, I've created a "modify" operation which is :
- get a transaction
- get the object obj1
- "modify it in my app" (for example obj = obj+1)
- put the new value
- commit transaction
This works but, in the following scenario, I get incoherent result, since get operations don't block.
Threads t1 and t2 modify the object obj1 at the same time. So, for example obj1 == 0 at the beginning. Then :
- t1 get a transaction
- t2 get a transaction
- t1 get the old obj1 value
- t2 get the old obj1 value
- t1 put the new value (obj1 == 1) in the cache;
- t2 put the new value (obj1 == 1) in the cache;
So at the end, obj1 == 1 in the cache, instead of 2!
obj1 = 0 + 1 (thread 1)
obj1 = 1 + 1 (thread 2, with old value == 1, thanks to thread 1)
I hope I'm clear enough...
So, my question is : what should I do?
Note that I can't say anything on the get/write operations ratio.
Should I use "put" operation to get the old value in modify operation (instead of get)? Won't it be heavy (in load term)?
Note that when I use TRANSACTION_GET_COMMITTED, the get of the "modify" operation doesn't block, but when I use TRANSACTION_REPEATABLE_GET, it is the get operation (the basic, not embedded in the modify operation) which is blocking.
I'd like : get basic operations don't be blocking and coherent "modify" operation. Is it possible?
Isn't it too heavy (in load) to block all the "modify" operation? What about versioning, to detect a change (between a get (old value) and put (new value))? Have code example?
Thanks for your advice,
Vincent
Message was edited by: Vincent

Hi Vincent,
It sounds like you can simply use locking in this scenario (cache locking semantics are similar to that of a Java synchronized keyword - if thread does use lock() it will block is there is contention, and if it doesnt use lock() it will not block at all):
read:
<code>
value = cache.get(key); // does not block
</code>
write:
<code>
try {
cache.lock(key, timeout); // will block if there is contention
value = cache.get(key);
cache.put(key, value + 1);
} finally {
cache.unlock(key);
</code>
Regards,
Dimitri

Similar Messages

  • FTP put and get

    When using FTP put and get to transfer files, the program does not go into passive mode. My website requires the following sequence of commands: TYPE A, PORT, PASV, RETR or STOR filename.
    Please update Windows FTP for XP & Windows 7 and later or provide me with the means of using raw FTP commands in my programs.

    Hello ray.crwfrd,
    Please explain a bit about the requirement in case of misunderstanding.
    What do you mean about the sentence ‘update Windows FTP for XP & Windows 7’?
    The following article is about the means of raw FTP command.
    http://www.nsftools.com/tips/RawFTP.htm
    Please note: Since the website is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Best regards,
    Fangzhou CHEN
    Fangzhou CHEN
    TechNet Community Support

  • Hwo to put and get data to a mq queue through java

    Hi All
    I would like to know how to put and get messages into a mq series server which is residing on another machine through a java program.
    I do not have a mq client installed in my machine..
    I have WSAD in my machine.... Should i definitely use a JMS for the same?
    PR.

    The MQ client installation is free. You can download it from ibm.com, install it, and refer to the application development documentation that accompanies the installation. I believe there are even sample java programs included in the installation.
    -Scott

  • PUT and GET Buttons disappeared?

    In the file panel the buttons for PUT and GET are not showing upp at all. What can I do?

    It sounds as though you set up a site selecting FTP & RDS Server. Select Site > New Site to define the site correctly.

  • Problem about put and get

    hi there,
    I met a problem, when i put the data, and get it.
    key data
    aaa aaaaaa
    bbb bbbbbb
    ccc cccccc
    I have put "aaa", "bbb" and "ccc" into db, but when I try to get the key for "aaa" , "bbb", it return the data "cccccc", how can I solve it?
    after that, when i get the key "ddd", "eee" , and all strings are length 3, the key does not in the DB, it also return the data "cccccc". Did I do something wrong on my code?
    void Set1(CString sKey)
    int ret;
    std::string sdb = "test.db";
    Db db(NULL, 0);
    ret = db.open(NULL,
         sdb.c_str(),
         NULL,
         DB_BTREE,
    DB_CREATE,
         0);
    std::string skey, sdata;
    skey = sKey;
    sdata.append(skey);
    sdata.append(skey);
    Dbt key(&skey, skey.length());
    Dbt data(&sdata, sdata.length());
    ret = db.put(NULL, &key, &data, 0);
    if(ret==0){
    TRACE("success\n");
    ret = db.close(0);
    void Get1(CString sKey)
    int ret;
    std::string sdb = "test.db";
    ret = db.open(NULL,
    sdb.c_str(),
         NULL,
         DB_BTREE,
         DB_CREATE,
         0);
    Dbc *cur;
    ret = db.cursor(NULL, &cur, 0);
    std::string skey, s2, a2;
    skey = sKey;
    Dbt key(&skey, skey.length());
    Dbt data;
    memset(&data, 0, sizeof(data));
    ret = cur->get(&key, &data, DB_SET);
    if(ret!=DB_NOTFOUND){
    a2 = (std::string*) data.get_data();
    s2 = (std::string*) key.get_data();
    TRACE("FOUND %s %s\n", s2->c_str(), a2->c_str());
    ret = cur->close();
    ret = db.close(0);
    }

    Hi,
    The problem seems to be with these lines:
    std::string skey, sdata;
    Dbt key(&skey, skey.length());
    Dbt data(&sdata, sdata.length());You are constructing a Dbt with data that is actually a pointer to a C++ std::string object. You want the value to be an actual c style string.
    An alternative would be to construct the Dbts like:
    Dbt key(skey.c_str(), skey.length());
    Dbt data(sdata.c_str(), sdata.length());You will need to create a new std::string out of any data retrieved from the database as well. Since it will now be just a C-style char * string.
    I hope this helps.
    Regards,
    Alex Gorrod, Oracle

  • Synchronizing put and select

    In Berkeley DB, Java Ed. When using non-transactionl context and deferred writes, I get select method failures. My application has one writer(put) and one reader(select) thread.
    I thought as soon as writer succesffuly returns, the record is inserted but possibly not on disk. It turns out, the record is nowhere yet. Select method of another thread who comes a bit later does not see it. I was able to fix it by synchronizing put and get methods. Did anybody run into this problem, is it true?
    thanks,
    eugene

    Hi Eugene,
    When you insert a record with JE with a non-transactional put() method (including with Deferred Write), it is available for querying in other threads when the put() method returns. There are no known bugs in this area.
    Since you are inserting and querying in two different threads, how do you know that the query occurs after the insert? Of course, if two threads must execute operations in a particular sequence, you must synchronize them correctly yourself.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • FTP get operation doesn't work. However put and syncRead works.

    Hello SOA Gurus,
    Here is the another strange challenge I faced today with FTP adapter.
    I have a JNDI which is commonly used to access an FTP server. Initially, I created one BPEL process that uses "put" operation to write a file into the FTP directory. It worked successfully.
    But when I used "get" operation with the same JNDI, it doesn't work there. However, I am consistently getting the below error messages in the server log:
    <Nov 28, 2014 4:20:48 AM EST> <Notice> <Stdout> <BEA-000000> <<Nov 28, 2014 4:20:48 AM EST> <Warning> <oracle.soa.adapter> <BEA-000000> <FTP Adapter MercentPollerPOC Th
    e connection variable is null in postCall. This could be because of a call postCall w/o a preceeding call to preCall.>>
    <Nov 28, 2014 4:21:18 AM EST> <Notice> <Stdout> <BEA-000000> <<Nov 28, 2014 4:21:18 AM EST> <Warning> <oracle.soa.adapter> <BEA-000000> <FTP Adapter MercentPollerPOC Th
    e connection variable is null in postCall. This could be because of a call postCall w/o a preceeding call to preCall.>>
    <Nov 28, 2014 4:21:48 AM EST> <Notice> <Stdout> <BEA-000000> <<Nov 28, 2014 4:21:48 AM EST> <Warning> <oracle.soa.adapter> <BEA-000000> <FTP Adapter MercentPollerPOC Th
    e connection variable is null in postCall. This could be because of a call postCall w/o a preceeding call to preCall.>>
    <Nov 28, 2014 4:22:18 AM EST> <Notice> <Stdout> <BEA-000000> <<Nov 28, 2014 4:22:18 AM EST> <Warning> <oracle.soa.adapter> <BEA-000000> <FTP Adapter MercentPollerPOC Th
    e connection variable is null in postCall. This could be because of a call postCall w/o a preceeding call to preCall.>>
    Any help would be appreciated. Thanks in advance.

    Hello!
    Can you check if this oracle metalink note 754029.1 is applicable?
    Though it talks of very old version of SOA but the changes are advised to make on FTP server.
    Hope it helps!
    Thanks

  • How to create Operating Unit/Department and Divisions in PP01 transaction

    Hi,
    1) Any body can tell me how to create the Operating unit, department and division in PP01 transaction.
    2) How to move one department to another operating unit  and etc.
    3) is ther any std report/ FM exists to get affected employees(I mean when i move one department to another operating unit (Y) i need employees who comes under this
    Regards,
    Maheedhar

    Issue solved.

  • Can I return my Ipod touch 4th generation and get an Ipad, if my Ipod is still under warranty?

    Can I return my Ipod touch 4th generation and get an Ipad 2, if my ipod is still under warranty?

    The warranty doesn't cover that. Sell it and put the money towards a new device.
    (79450)

  • When i put a cd into my itunes library sometimes it does not get stored under the same cover. sometimes stored under 3 or 4 different icons. what can i do to prevent this. how do i get all the songs back under the same kicon in one place? help would be a

    sometimes when i put a new cd into my itunes libray all the songs do not end up under the same icon. sometimes it will go into the library under 3 or 4 different icons (album artwork) and sometimes if there are for example 12 songs on the cd each song goes under a separate icon.this seams to happen more frequently with cd's that have different artists on one disc and not just one artist performing all the songs.
    is there anyway to prevent this from happening?
    is there a way to go into my library and get them put back under one icon as it should have been? i have tried drag and drop and it will not work.
    thanks to anyone that can offer some help

    The sort fields should generally be empty unless you've putting in custom values to sort solo artists by their surnames. You can apply common changes to thousands of tracks at once, just don't apply the wrong change because there is no undo.
    It is a good idea to backup before undertaking large scale changes. See this backup tip for a suggested approach.
    tt2
    Message was edited by: turingtest2

  • Can we call a transaction in background and get the list in report?

    I want to call the standard T-Code MC.9 from a report in background using Call Transaction and get the list in the report.There are some enhancement done to its base program RMCB0300 due to which if I use Submit ... exporting to memory and then import the list from memory, the result doesnt match to the values given by T-Code MC.9.
    The option apparently for me is to use Call Transaction method, but if I use Call transaction method, how do I make the report to be executed in background and then get the resultant list in the report?

    Copy the program in Z and than modify it saving the list on memory on database table.

  • I''m new to Mac, how do I install Adobe CD? I put it in the CD drive and get a menu, everything I click on goes nowhere. In Microsoft, I installed many programs with no problem

    I''m new to Mac, how do I install Adobe CD? I put it in the CD drive and get a menu, everything I click on goes nowhere. In Microsoft, I installed many programs with no problem

    Is the Adobe CD a MAC app ?
    If it is a program for Windows you will not be able to install it.
    If you nedd that program you can either buy the equivalent for Mac or install a way to run Windows under Mac (may be a cheaper solution)

  • I purchased 3 ringtones from itunes.  It did not put them under ringtones on my phone.  It is under purchases.  How can I get them under ringtones for iphone 5?

    I purchased 3 ringtones in Itunes.  It put one under ringtones and the others listed under music icon as recently purchased.  How do I get them under ringtones?

    Tones is the new name for Ringtones. If the entry is missing in the left-hand column of iTunes then enable it from Edit > Preferences > General tab.
    If your existing tones are not syncing properly to your iOS device then uncheck the option to Sync Tones from the Tones tab when the device is connected, sync the device, check the option and sync again.
    tt2

  • I think someone might be hacking my computer.  I downloaded a free game last night and since then under the shared tab in my finder it says "hp002655a82ea0" and the only info I can get about it is that it is a pc.

    I downloaded a free game last night and since then under the shared tab in my finder it says "hp002655a82ea0" and the only info I can get about it is that it is a pc.  Then under console I see several "stealth mode connection" attempts ti TCP 192.168.1.107:##### from 74.125.225.82.443.  The second number has jumped around and sometimes starts with 192.  I dont really know what those numbers are but how do I stop them from attempting to get through my firewall and kick them out of my shared tab???  I encrypted all my files and made sure all sharing is turned off so I don't know what they are doing.  Thank you very much.

    Mac OS X versions 10.6.7 and later have built-in detection of known Mac malware in downloaded files. The recognition database is automatically updated once a day; however, you shouldn't rely on it, because the attackers are always at least a day ahead of the defenders. In most cases, there’s no benefit from any other automated protection against malware.
    The most effective defense against malware is your own intelligence. All known Mac malware takes the form of trojans that can only operate if the victim is duped into running them. If you're smarter than the malware attacker thinks you are, you won't be duped. That means, primarily, that you never install software from an untrustworthy source. How do you know a source is untrustworthy?
    Any website that prompts you to install software, such as a “codec” or “plug-in,” that comes from that same site, or an unknown site, is untrustworthy.
    A web operator who tells you that you have a “virus,” or that anything else is wrong with your computer, or that you have won a prize in a contest you never entered, is trying to commit a crime with you as the victim.
    “Cracked” versions of commercial software downloaded from a bittorrent are likely to be infected.
    Software with a corporate brand, such as Adobe Flash, must be downloaded directly from the developer’s website. No intermediary is acceptable.
    Follow these guidelines, and you’ll be as safe from malware as you can reasonably be.
    Never install any commercial "anti-virus" products for the Mac, as they're all counter-productive. If you need to be able to detect Windows malware in your files, use ClamXav -- nothing else.

  • I have an iphone 4 for verizon and i am going to switch phones and get a droid motorolla 4g phone and the droid doesnt have a sim card. does my iphone 4 have a sim card that i can put in the droid? can i buy sim cards separately online for the droid?

    i have an iphone 4 for verizon and i am going to switch phones and get a droid motorolla 4g phone and the droid doesnt have a sim card. does my iphone 4 have a sim card that i can put in the droid? can i buy sim cards separately online for the droid?

    Brandon2184 wrote:
    The iPhone 4 uses a "Nano SIM"
    The CDMA iPhone 4 does not use a SIM at all. There is no SIM slot. It is a pure CDMA phone.

Maybe you are looking for

  • User Interface Guidelines for CRM 2007 are now available

    The CRM UI Concept Team has made the [UI Guidelines for CRM Web Client User Interface (CRM 2007 UI)|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/302d8152-002b-2b10-34bd-9ff3c712dd4b] available to the BPX community: This documen

  • How to upgrade the xoom to 4G without sending it in to Motorola

    The upgrade to 4G is an easy process that takes less than 10 minutes, but if your like me, you may be leery to send your Xoom into Motorola and be without it for a week. There is no way to truly remove the data on the sdcard without overwriting it mu

  • JAVAMail API

    Anyone have any idea's on this error message when I run my JAVA Code: Error Below. The thing is if I use a internal E-mail TO: address the mail and attachement is send. This only happens when I try to send a letter outside the firms MS Exchange serve

  • Can I connect most any DVI Monitor to a MacBook Air with the right adapter

    Anybody have any luck doing this?

  • Flagging a photo - lost function

    I used to be able to click in top right hand corner of a photo and it would flag it. Somehow I have lost this along with the star rating at the bottom left hand corner. Any suggestions as to what I can do to get these back. Thanks