Oracle dead lock deep research.
Update SQLS will lead dead lock exception. Because by default, it use optimistic lock but not pessimistic lock.
Below description is exceprted from the attachment(It exceeds my image that this blog can not upload the attachment,hehe)
Optimistic locking offers an elegant solution to the problems outlined above. Optimistic locking does
not lock records when they are read, and proceeds on the assumption that the data being updated has not
changed since the read. Since no locks are taken out during the read, it doesn’t matter if the user goes to
lunch after starting a transaction, and deadlocks are all but eliminated since users should never have to
wait on each other’s locks
There are some ways to resolve this problem.
1. Create a pessimistic lock. Change the sql like below formal.
First: select … from … for update nowait
Second: update the resultSet.
2. Execute the SQL again after a random duration when program meets this kind of exception. (It will consume lot of db server resource. I don't think it is the better way)
3. Schedule the SQL executed sequenced or split data without interfere.
Ïà¹ØÎĵµ£º
¡¾ÑµÁ·6.1¡¿¡¡Ê¹ÓÃÒþʽÓαêµÄÊôÐÔ£¬Åж϶ԹÍÔ±¹¤×ʵÄÐÞ¸ÄÊÇ·ñ³É¹¦¡£
²½Öè1£ºÊäÈëºÍÔËÐÐÒÔϳÌÐò£º
BEGIN
UPDATE emp SET sal=sal+100 WHERE empno=1234;
IF SQL%FOUND THEN
DBMS_OUTPUT.PUT_LINE('³É¹¦Ð޸ĹÍÔ±¹¤×Ê£¡');
......
•ºÎΪÉó¼Æ
Êý¾Ý¿âÉ󼯣¬¾ÍÊǶÔÊý¾Ý¿âµÄ»î¶¯×ö¸ú×ټǼ£¬Ö÷Òª°üÀ¨Êý¾Ý¿âÁ¬½Ó£¬SQLÓï¾äÖ´ÐУ¬Êý¾Ý¿â¶ÔÏó·ÃÎÊÕâЩ·½ÃæµÄ¸ú×ټǼ¡£
•ÏÖʵ×÷ÓÃ
°²È«¿ØÖÆ¡¢¸ú×ÙÊý¾Ý±ä»¯¡¢³ÌÐòBUGµ÷ÊÔ¡¢×Ô¶¨ÒåµÄÊý¾Ý»ã×Ü·ÖÎö¡¢²Ù×÷ÈÕÖ¾
•´æ´¢·½Ê½
Ò»ÖÖÊÇ´æ´¢ÔÚ²Ù×÷ϵͳÎļþÖУ¬Ò»ÖÖÊÇ´æ´¢ÔÚsystem±í¿Õ¼äÖеÄSYS.AUD$±íÖÐ
......
Âò±¾Êé ÏÈ´Ó°²×°¿ªÊ¼°É È»ºóÂò±¾PLSQL ѧѧÓï·¨ ÕâÊÇ×î»ù±¾µÄ ½ÓÏÂÀ´¾ÍÑо¿¹ÊÕϺóÔõôÐÞ¸´ ÔÙ¾ÍÊDZ¸·Ý ÓÅ»¯ ¼¯Èº È»ºó»¹ÒªÑ§Ï°LINUX²Ù×÷ ÕâÊÇÒ»¶¨ÒªµÄ ×°WINDOWSÉϵÄORACLE²»¶à ÔÙ»¨2WÈ¥¿¼¸öOCP ¾ÍÐÐÁË
oracleµÄ¹Ù·½½Ì²ÄµÄ˳ÐòÊÇsql»ù´¡£¬½á¹¹£¬±¸·Ý»Ö¸´£¬ÐÔÄÜÓÅ»¯¡£
sqlÓï¾äµÄ»ù´¡»¹ÊǺÜÖØÒªµÄ¡£Èç¹ûÄãÏë×ö¿ª·¢pl/sqlÒ» ......
ÎÄÕÂÒ»£ºSCNÊÇʲô£¿The System Change Number
system change number (SCN)ÊÇÒ»¸ö·Ç³£ÖØÒªµÄ±ê¼Ç£¬OracleʹÓÃËüÀ´±ê¼ÇÊý¾Ý¿âÔÚ¹ýȥʱ¼äÄÚµÄ״̬ºÍ¹ì¼£¡£
OracleʹÓÃSCNÀ´±£´æËùÓб仯µÄ¹ì¼£¡£SCNÊÇÒ»¸öÂ߼ʱÖÓÀ´¼Ç¼Êý¾Ý¿âʼþ¡£Ëü·Ç³£µÄÖØÒª£¬²¢²»ÊÇÖ»ÊÇΪÁ˻ָ´¡£
SCNÓеãÀàËÆÓÚsequence£¬OracleÔÚSGAÖÐÔ ......
/**
*
*/
package com.huawei.widget.util;
import java.math.BigDecimal;
/**
* @author tanjixuan
* @since 2008-12-20
*
*/
public final class DatabaseUtil
{
// oracleתÒå×Ö·û
public static final char ORACLE_ESCAPE_CHAR = '\\';
// orac ......