草庐IT

thread_category_id

全部标签

java - 在 Java 中使用 Thread#stop() 来终止一个正在运行的线程是否可以接受?

遗憾的是,在Java中对字符串使用正则表达式时无法指定超时。因此,如果您没有严格控制将哪些模式应用于哪些输入,您最终可能会拥有消耗大量CPU的线程,同时无休止地尝试将(设计不佳的)模式与(恶意的?)输入匹配。我知道Thread#stop()被弃用的原因(参见http://download.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html)。它们以可能在ThreadDeath异常情况下损坏的对象为中心,然后这些对象会污染您正在运行的JVM环境并可能导致细微的错误。对于比我对JVM的工作原理有更深

java - SwingUtilites : how to return values from another thread in Java?

我正在尝试用Java开发一个应用程序。为了使Swing正常工作,我这样做了:publicstaticvoidmain(String[]array){StringouterInput;SwingUtilities.invokeLater(newRunnable(){@Overridepublicvoidrun(){//Iwantthisstringinput.Stringinput=JOptionPane.showInputDialog(null,"Stop?",JOptionPane.QUESTION_MESSAGE);});//HowcanIgetthisinputvalueinSt

java - 如何在 Spring WebSocketStompClient 中获取 Session Id?

如何在JavaSpringWebSocketStompClient中获取sessionID?我有WebSocketStompClient和StompSessionHandlerAdapter,它们可以很好地连接到我服务器上的websocket。WebSocketStompClient使用SockJsClient。但我不知道如何获取websocket连接的sessionID。在客户端带有stompsession处理程序的代码中privateclassProducerStompSessionHandlerextendsStompSessionHandlerAdapter{...@Overr

java - 为什么 Thread 类不是最终的?你为什么要扩展一个线程?

我得到这个作为面试问题。whyisn'tThreadclassfinal?WhywouldyouextendaThreadever?我想不出真实世界的用例。 最佳答案 来自Oracle'sdocumentation:Therearetwowaystocreateanewthreadofexecution.OneistodeclareaclasstobeasubclassofThread.ThissubclassshouldoverridetherunmethodofclassThread.Theotherwaytocreateath

java - Hibernate 未知的 ids 整数数据类型

我刚开始使用Hibernate,我遇到了一个我无法弄清楚的错误。我有以下类(class):@Entity@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)publicabstractclassAbstractColumn{@Id@GeneratedValue(strategy=GenerationType.AUTO)privateStringid;privateStringname;//Otherstuff}然后我有@EntitypublicclassDoubleColumnextendsAbstractColumnimplem

java - 如何在分布式环境中预取 Oracle 序列 ID

我有一个在5个应用程序服务器上运行的分布式Java应用程序。这些服务器都使用在第6台机器上运行的相同Oracle9i数据库。应用程序需要从序列中预取一批100个ID。在单线程、非分布式环境中做起来相对容易,您只需发出以下查询即可:SELECTseq.nextvalFROMdual;ALTERSEQUENCEseqINCREMENTBY100;SELECTseq.nextvalFROMdual;第一个选择获取应用程序可以使用的第一个序列ID,第二个选择返回最后一个可以使用的序列ID。在多线程环境中,事情变得更加有趣。您不能确定在第二次选择之前另一个线程不会再次将序列增加100。这个问题可

java.lang.OutOfMemoryError : unable to create new native thread 错误

我看到了这样的评论oneplaceihaveseenthisproblemisifyoukeepcreatingthreads,andinsteadofcallingstart(),callrun()directlyonthethreadobject.Thiswillresultinthethreadobjectnotgettingdereferenced...Soaftersometimethemessageunabletocreatenewnativethreadcomesup关于SunJavaForums在我的应用程序中,最初我们计划使用线程,但后来我们决定不再需要,所以我们只调

java - 插入行并获取生成的 ID

我正在尝试使用Spring的JdbcTemplate类将一行插入到名为transaction的MySQL表中并获取生成的ID。相关代码为:publicTransactioninsertTransaction(finalTransactiontran){//WillholdtheIDoftherowcreatedbytheinsertKeyHolderkeyHolder=newGeneratedKeyHolder();getJdbcTemplate().update(newPreparedStatementCreator(){publicPreparedStatementcreatePr

java - 为什么我应该使用 Runnable 而不是 Thread?

这个问题在这里已经有了答案:"implementsRunnable"vs"extendsThread"inJava(43个回答)关闭7年前。我只是学习线程的理论。还有Thread和Runnable。classAextendsThread{publicvoidrun(){while(true){System.out.println("Hi");}}}classBimplementsRunnable{publicvoidrun(){System.out.println("Hi");}}Thread有丰富的API,为什么我要使用Runnable而不是Thread?谢谢。

java - JPA/Spring/Delete Entity,类型不匹配(int/long for id)

我有一个使用的实体@Id@GeneratedValue(strategy=GenerationType.AUTO)privatelongid;我有这个实体的JPA存储库。现在我想删除其中一个,但标准方法是delete(inti),它不起作用,因为我的ID不是整数,而是长整数。那么除了使用int作为我的ID之外,在这里还能做什么?我可以指定一个使用long的自定义删除方法,就像它与findbyXX(XX)一起使用一样吗?编辑:首先:是的,我正在使用DataJPA!我想这样做:jparepository.delete(id);如果id是一个整数:org.hibernate.TypeMism