From: <jtc...@li...> - 2006-02-14 18:55:15
|
Update of /cvsroot/jtcfrost/frost-wot/source/frost/threads In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11980/source/frost/threads Modified Files: MessageUploadThread.java Log Message: fixes Index: MessageUploadThread.java =================================================================== RCS file: /cvsroot/jtcfrost/frost-wot/source/frost/threads/MessageUploadThread.java,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** MessageUploadThread.java 14 Feb 2006 17:36:57 -0000 1.81 --- MessageUploadThread.java 14 Feb 2006 18:55:04 -0000 1.82 *************** *** 634,638 **** int index = 0; int tries = 0; ! int maxTries = 5; boolean error = false; boolean tryAgain; --- 634,638 ---- int index = 0; int tries = 0; ! int maxTries = 8; boolean error = false; boolean tryAgain; *************** *** 641,648 **** boolean retrySameIndex = false; while (!success) { if( retrySameIndex == false ) { ! // find first free index slot index = findNextFreeIndex(index); if( index < 0 ) { --- 641,650 ---- boolean retrySameIndex = false; + File lockRequestIndex = null; while (!success) { + if( retrySameIndex == false ) { ! // find next free index slot index = findNextFreeIndex(index); if( index < 0 ) { *************** *** 652,674 **** continue; } } else { // reset flag retrySameIndex = false; } - // probably empty, check if other threads currently try to insert to this index - File lockRequestIndex = new File(composeMsgFilePath(index) + ".lock"); - boolean lockFileCreated = lockRequestIndex.createNewFile(); - - if (lockFileCreated == false) { - // another thread tries to insert using this index, try next - index++; - logger.fine("TOFUP: Other thread tries this index, increasing index to " + index); - continue; // while - } else { - // we try this index - lockRequestIndex.deleteOnExit(); - } - // try to insert message String[] result = new String[2]; --- 654,678 ---- continue; } + + // probably empty slot, check if other threads currently try to insert to this index + lockRequestIndex = new File(composeMsgFilePath(index) + ".lock"); + boolean lockFileCreated = lockRequestIndex.createNewFile(); + + if (lockFileCreated == false) { + // another thread tries to insert using this index, try next + index++; + logger.fine("TOFUP: Other thread tries this index, increasing index to " + index); + continue; // while + } else { + // we try this index + lockRequestIndex.deleteOnExit(); + } + } else { // reset flag retrySameIndex = false; + // lockfile already created } // try to insert message String[] result = new String[2]; *************** *** 700,704 **** int dlMaxTries = 2; while(dlTries < maxTries) { ! try { Thread.sleep(10000); } catch(InterruptedException e) {} tmpFile.delete(); // just in case it already exists downloadMessage(index, tmpFile); --- 704,708 ---- int dlMaxTries = 2; while(dlTries < maxTries) { ! Mixed.wait(10000); tmpFile.delete(); // just in case it already exists downloadMessage(index, tmpFile); *************** *** 730,734 **** index++; logger.warning("TOFUP: Upload collided, increasing index to " + index); ! try { Thread.sleep(10000); } catch(InterruptedException e) {} } } else { --- 734,738 ---- index++; logger.warning("TOFUP: Upload collided, increasing index to " + index); ! Mixed.wait(10000); } } else { *************** *** 741,750 **** tries++; retrySameIndex = true; ! try { Thread.sleep(10000); } catch(InterruptedException e) {} } } } ! // finally delete the index lock file ! if (lockFileCreated == true ) { lockRequestIndex.delete(); } --- 745,754 ---- tries++; retrySameIndex = true; ! Mixed.wait(10000); } } } ! // finally delete the index lock file, if we retry this index we keep it ! if (retrySameIndex == false) { lockRequestIndex.delete(); } |