草庐IT

single-thread

全部标签

Java:测试线程访问 "not thread-safe"方法

我在SwingJava应用程序中解决线程问题的策略是将方法分为三种类型:应该由GUI线程访问的方法。这些方法不应该阻塞并且可以调用swing方法。不是线程安全的。应由非GUI线程访问的方法。基本上这适用于所有(潜在的)阻塞操作,例如磁盘、数据库和网络访问。他们不应该调用swing方法。不是线程安全的。两者都可以访问的方法。这些方法必须是线程安全的(例如同步的)我认为这对于通常只有两个线程的GUI应用程序来说是一种有效的方法。解决问题确实有助于减少竞争条件的“表面积”。当然,需要注意的是,您绝不会不小心从错误的线程中调用方法。我的问题是关于测试的:是否有测试工具可以帮助我检查是否从正确的

java - Thread.currentThread().sleep(timer) vs Thread.sleep(time);

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:Java:Thread.currentThread().sleep(x)vs.Thread.sleep(x)...之间有什么区别Thread.currentThread().sleep(time)和Thread.sleep(time);还有一件事是我可以在不使用线程类的情况下延迟程序的任何其他方法...

java - 如何在单元测试中避免 Thread.sleep?

假设我有以下应该测试的方法:@AutowiredprivateRoutingServiceroutingservice;publicvoidmethodToBeTested(){ObjectobjectToRoute=initializeObjectToRoute();if(someConditions){routingService.routeInOneWay(objectToRoute);}else{routingService.routeInAnotherWay(objectToRoute);}}在这种情况下,RoutingService在单独的线程中运行,因此在它的构造函数中我

Self-supervised Single-view 3D Reconstruction via Semantic Consistency论文笔记

Self-supervisedSingle-view3DReconstructionviaSemanticConsistency论文地址:https://arxiv.org/abs/2003.06473作者:XuetingLi,SifeiLiu,KihwanKim,ShaliniDeMello,VarunJampani,Ming-HsuanYang,andJanKautz发表:ECCV2020链接:https://github.com/NVlabs/UMR笔记参考:https://zhuanlan.zhihu.com/p/464151329Abstract该模型通过收集二维图像和轮廓来预测目标

java - 请解释 Thread run() 和 start() 方法的输出

请解释以下代码的输出:如果我调用th1.run(),输出是:EXTENDSRUN>>RUNNABLERUN>>如果我调用th1.start(),输出是:RUNNABLERUN>>EXTENDSRUN>>为什么会出现这种不一致?请解释。classThreadExampleextendsThread{publicvoidrun(){System.out.println("EXTENDSRUN>>");}}classThreadExampleRunnableimplementsRunnable{publicvoidrun(){System.out.println("RUNNABLERUN>>

java - 如何避免使用 Thread.Sleep

在我下载最新版本的Netbeans之前,我从未考虑过Thread.Sleep的使用。Netbeans现在警告您不要使用Thread.Sleep。因此,我对该主题进行了一些研究,发现有人说您只需要将Thread.Sleep用于调试/测试目的,如果您在任何其他时间使用它,您的代码就会写得不好。所以我的问题是在以下情况下如何避免使用Thread.Sleep。我编写了一个与另一个应用程序交互的服务器应用程序。服务器有两个线程:处理来自套接字的数据并发回其他信息或只是简单的确认。这是主线程。启动套接字线程后,它会进入一个无限期的while循环。在这个while循环中,我检查以确保套接字线程仍然处

java - Jackson JSON - 解码时出现 "no single-String constructor/factory method"错误

最简单的情况给我带来了麻烦。我第一次遇到它。我能够解码稍微复杂的json,但这个简单的失败了。什么会导致这种情况?为什么jackson只用一个字符串就有问题?保存用户角色名称的简单类。publicclassUpdateUserRole{privateStringname;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}}Controller内部publicvoidupdateUserRole(@PathVariableLongid,@RequestBodyUpdateUser

java.rmi.ServerException : RemoteException occurred in server thread (ClassNotFoundException) 异常

以下方法:privatevoidstartServer(){//snippetthatstartstheserveronthelocalmachinetry{RemoteMethodImplimpl=newRemoteMethodImpl();Naming.rebind("Illusive-Server",impl);}catch(Exceptionexc){JOptionPane.showMessageDialog(this,"Problemstartingtheserver","Error",JOptionPane.ERROR_MESSAGE);System.out.println

java - Thread.sleep 等待时间超过预期

以下代码:longmsBefore=System.currentTimeMillis();//Thread.currentThread().setPriority(Thread.MAX_PRIORITY);try{Thread.sleep(200);}catch(InterruptedExceptione){}System.out.println("Time:"+(System.currentTimeMillis()-msBefore));打印:Time:578Time:594Time:625Time:640Time:641Time:609Time:625Time:625Time:61

java - hibernate 异常 : Could not obtain transaction-synchronized Session for current thread

我遇到错误:Exceptioninthread"main"org.hibernate.HibernateException:Couldnotobtaintransaction-synchronizedSessionforcurrentthread主要ppService.deleteProductPart(cPartId,productId);@Service("productPartService")@OverridepublicvoiddeleteProductPart(intcPartId,intproductId){productPartDao.deleteProductPart