1

我正在尝试在 mysql 数据库中使用两个不同的线程插入。插入是由准备好的语句完成的。批量插入 500 个。

//g1 是全局对象,可被实现可运行的类访问

    ExecutorService executor = Executors.newCachedThreadPool();

    Callable< Map<String, Set<String>>> callable2 = new PolyStrain();
    Callable<Map<String, Phenotype>> callable3 =  new DataPolymor();


    g1.kol=new HashMap<String, Set<String>>();

    g1.mapPheno = new HashMap<String, Phenotype>();


    Future<Map<String, Set<String>>> future = executor.submit(callable2); // hashmap of allele and strains
    Future<Map<String, Phenotype>> future1 = executor.submit(callable3); //hashmap of allele and chro,location

    g1.kol = future.get();
    System.out.println(g1.kol.size());


    g1.mapPheno= future1.get();

    System.out.println(g1.mapPheno.size());

    executor.shutdown();

    InsertStrain dp1 = new InsertStrain(); //data entry for allele and strain and frequency
    Thread t1= new Thread(dp1);
    t1.start();

    InsertPheno ip1 = new InsertPheno();
    Thread t2 = new Thread(ip1);
    t2.start();

我面临的问题是,线程二开始了,但是,它不适用于插入。线程 dp1 完成其任务。dp1 完成后抛出以下内容:

Lock wait timeout exceeded; try restarting transaction 

我已经设置

mysql> SELECT @@GLOBAL.tx_isolation, @@tx_isolation, @@session.tx_isolation;

还,

mysql> set innodb_lock_wait_timeout=100

我想知道,即使线程 2 启动,为什么它不开始插入?任何帮助将不胜感激。提前谢谢了。

4

0 回答 0