0

我试图在各种留言板上找到我的问题的解决方案。但是,我正在撞墙。我正在尝试在 Mysql INNODB 表上重新创建我们的数据库“LockWait Timeout”上发生的问题。(有关我正在尝试解决的问题的信息,请访问:http ://bugs.mysql.com/bug.php?id=10641 )我已经缩小了问题范围,并且有一个解决方案。但我无法在测试环境中重新创建问题,因此我可以测试我的解决方案。

这是我的代码:

public static void main(String[] args) {        

    System.out.println("Programm Starting");

    int numberOfthreads = 2;

    for(int x = 1; x <= numberOfthreads; x++){
        //Create the object UpdateClass


        // Create the Runable object
        Runnable r = new Runnable() {
            // Start the Runnable
            public void run() {
                    System.out.println("Running");
            }
        };

        Thread thr = new Thread(r);
        System.out.println("Thread object created");

        thr.start();
        final UpdateClass session = new UpdateClass(x);
        System.out.println("Thread object started");

        try {
            System.out.println("Starting UpdateClass.runProcess()");
            session.runProcess();
            Thread.sleep(1);
        } 
        catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        thr.stop();

        System.out.println("Thread stopped");
    }
}

基本上,我试图将同步更新复制到 MySql 表以创建 LockWait Timeout 问题。

我的类 UpdateClass 按我需要的方式工作,但我无法重新创建同时事件来调用该类。

问题:如何更改我的代码以增加生成导致超时的条件的可能性?

4

1 回答 1

0

您可以尝试在测试中复制该问题的几件事:

  1. 将mysqlcnf中的innodb_lock_wait_timeout改为小时间间隔或增加线程休眠时间(如果更改cnf文件,需要重启DB服务器)
  2. 确保您在线程进入睡眠状态之前持有锁(并且尚未释放它)(您可能会在锁尚未释放但不完全确定的情况下通过网络断开/数据库连接断开来实现相同的效果) )。

我假设您的 MySQL 版本与生产中的版本相同。

于 2012-07-17T02:48:52.340 回答