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.
Ïà¹ØÎĵµ£º
²éѯÐÇÆÚ¼¸:
select to_char(sysdate,'day') from dual;
²éѯ¼¸ºÅ:
select to_char(sysdate,'dd') from dual;
²éѯСʱÊý:
select to_char(sysdate,'hh24') from dual;
²éѯʱ¼ä:
select to_char(sysdate,'hh24:mi:ss') from dual;
²éѯÈÕÆÚʱ¼ä:
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
²é ......
ôßÉÏͨ¹ýÔ¤±àÒë²ûÊöµÀ¹²Ïí³Ø×îºóµ½SGA£¬ÕâÀï½øÒ»²½ËµÃ÷Ò»ÏÂSGAÖÐÁíÒ»¸ö´ó¿é£¬Êý¾Ý»º³åÇø¡£
Ê×ÏÈÁ˽âÏÂSGAÖÖ´óÖÂÓÐÄÇЩ¶«Î÷£¬ÕâЩ¶«Î÷Ëæ×ÅÊý¾Ý¿â°æ±¾µÄÔö¼Ó»áÓÐËùÔö¼Ó£¬²»¹ý´óÖÂÉÏÓ¦¸ÃÒ»Ö£¬ÕâÒ²ÊÇ»ù±¾ËùÓеÄÌåϵ½á¹¹¶¼»áÃèÊöµÄ¶«Î÷£º ......
package DBbean;
import java.sql.*;
public class ConnBean
{
private Connection con;
//³õʼ»¯Á¬½Ó¡£
public ConnBean()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
......
ÎÄÕÂÒ»£ºSCNÊÇʲô£¿The System Change Number
system change number (SCN)ÊÇÒ»¸ö·Ç³£ÖØÒªµÄ±ê¼Ç£¬OracleʹÓÃËüÀ´±ê¼ÇÊý¾Ý¿âÔÚ¹ýȥʱ¼äÄÚµÄ״̬ºÍ¹ì¼£¡£
OracleʹÓÃSCNÀ´±£´æËùÓб仯µÄ¹ì¼£¡£SCNÊÇÒ»¸öÂ߼ʱÖÓÀ´¼Ç¼Êý¾Ý¿âʼþ¡£Ëü·Ç³£µÄÖØÒª£¬²¢²»ÊÇÖ»ÊÇΪÁ˻ָ´¡£
SCNÓеãÀàËÆÓÚsequence£¬OracleÔÚSGAÖÐÔ ......