为什么有#pool; pool pool-1-thread-1" Thread中的异常

时间:2014-12-08 20:18:13

标签: java jdbc

以下代码:

ExecutorService executor = newSingleThreadExecutor();
executor.execute(new Runnable()
            {
                @Override
                public void run()
                {
                    Session session = (Session) entityManager.getDelegate();
                    SQLQuery query = session.createSQLQuery("SELECT * FROM function()");
                    boolean result= (boolean) query.uniqueResult();
                }
            }

我得到一个例外:

Exception in thread "pool-1-thread-1" java.lang.NullPointerException
    at personDao$1.run(PersonDao.java:1080)

所以它在boolean result= (boolean) query.getUniqueResult();的行上说,有一个池1线程1,为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

名称"pool-1-thread-1"来自ExecutorService

如果你的信息是NPE发生在

boolean resul t = (boolean) query.getUniqueResult();

是真的,它可能是以下两个原因之一:

  • querynull
  • query.getUniqueResult()返回null(boolean) (Boolean) null throws NullPointerException