您没有释放获取的资源(DB连接和非守护进程线程)。
public class Test {
@Inject
Provider<EntityManager> em;
@Inject
UnitOfWork unitOfWork;
public void test() {
if(em.get().isOpen())
System.out.println("EM open");
unitOfWork.end(); // releases DB connection
}
public static void main(String args[]) {
final Injector injector = createInjector(new DatabaseModule());
Test app = injector.getInstance(Test.class);
app.test();
System.out.println("Done");
injector.get(PersistService.class).stop(); // releases resources acquired by the underlying EntityManagerFactory
}
}
@Transactional
注释或手动结束相应的工作单元(如上例所示)。