简体   繁体   English

SwingWorker - 在没有 Swing-Gui 的情况下的替代方案

[英]SwingWorker - alternative in cases without Swing-Gui

I really like the javax.swing.SwingWorker , it's such a easy way to handle Multithreading.我真的很喜欢javax.swing.SwingWorker ,它是一种处理多线程的简单方法。

Now I have a server-application without any GUI and want to use something like the SwingWorker , with the process() , done() , cancel() , etc...-methods.现在我有一个没有任何 GUI 的服务器应用程序,并且想要使用SwingWorker类的东西,以及process()done()cancel()等......方法。

I know I could just use the swing worker and probably have no problem, but still the swing worker obviously is intended to be used together with a swing-application.我知道我可以只使用 Swing Worker 并且可能没有问题,但是 Swing Worker 显然仍打算与 Swing 应用程序一起使用。

So is there anything like the swing worker that is intended to be used in more general cases, but pretty much does the same?那么有没有像 Swing Worker 那样的东西打算在更一般的情况下使用,但几乎是一样的?

Or if not so, what are the disadvantages of using swing worker and not working with Swing?或者如果不是这样,使用 Swing Worker 而不使用 Swing 有什么缺点? What comes to my mind is bad code-style and the done() and process() - method being executed in the EDT.我想到的是糟糕的代码风格以及在 EDT 中执行的done()process()方法。

Most server frameworks expect that you will not attempt to manage threads by yourself.大多数服务器框架都希望您不会尝试自己管理线程。 This is usually due to the way they are implemented (resources sur as transactions, security principal, loggers...) might be thread locals.这通常是由于它们的实现方式(作为事务、安全主体、记录器等的资源)可能是线程局部变量。 Most of the API are outright not thread-safe, for instance a JDBC connection is not.大多数 API 完全不是线程安全的,例如 JDBC 连接不是。

For instance the J2EE restrictions indicate that you should not create or manage threads.例如, J2EE 限制表明您不应创建或管理线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM