首页 \ 问答 \ NIO和JMS有什么区别(What is the difference between NIO and JMS)

NIO和JMS有什么区别(What is the difference between NIO and JMS)

据我所知Java NIO是一个API来帮助创建事件驱动的应用程序。 您在哪里使用选择器来通知您的应用程序通过SocketChannel接收到的任何数据。 JMS(Java消息传递服务)是用于在客户端之间发送/接收消息的消息传递框架。

JMS是Java NIO API的抽象吗?


As I understand Java NIO is an API to help create event-driven applications. Where you use a selector to notify your application of any data received over a SocketChannel. JMS(Java Messaging Service) is a messaging framework for sending/receiving messages between clients.

Is JMS a abstraction of Java NIO API?


原文:https://stackoverflow.com/questions/5051383
更新时间:2023-10-08 07:10

最满意答案

守护线程不会阻止应用程序退出。 程序在所有非守护线程(包括主线程)完成时结束。

因此,一般来说,如果您在后台执行某些操作,则可能需要将该线程设置为守护程序,以便在应用程序退出之前不必显式地使该线程的函数返回。

例如,如果您正在编写GUI应用程序,并且用户关闭了主窗口,则程序应该退出。 但是如果你有非守护线程挂起,它不会。

从文档: http : //docs.python.org/library/threading.html#threading.Thread.daemon

它的初始值是从创建线程继承的; 主线程不是守护进程线程,因此在主线程中创建的所有线程都默认为守护程序= False。

当没有活动的非守护进程线程时,整个Python程序将退出。


A daemon thread will not prevent the application from exiting. The program ends when all non-daemon threads (main thread included) are complete.

So generally, if you're doing something in the background, you might want to set the thread as daemon so you don't have to explicitly have that thread's function return before the app can exit.

For example, if you are writing a GUI application and the user closes the main window, the program should quit. But if you have non-daemon threads hanging around, it won't.

From the docs: http://docs.python.org/library/threading.html#threading.Thread.daemon

Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when no alive non-daemon threads are left.

相关问答

更多
  • 如果你为python线程指定了thread.daemon = True ,那么当只有守护进程被留下时,程序会立即停止。 发送到stdout的命令会丢失。 将其添加到名为main.py的文件中 import threading import time def int_sleep(): for _ in range(1, 600): time.sleep(1) print("sleep") def main(): thread = threading.Thread(target=in ...
  • 守护线程不会阻止应用程序退出。 程序在所有非守护线程(包括主线程)完成时结束。 因此,一般来说,如果您在后台执行某些操作,则可能需要将该线程设置为守护程序,以便在应用程序退出之前不必显式地使该线程的函数返回。 例如,如果您正在编写GUI应用程序,并且用户关闭了主窗口,则程序应该退出。 但是如果你有非守护线程挂起,它不会。 从文档: http : //docs.python.org/library/threading.html#threading.Thread.daemon 它的初始值是从创建线程继承的; 主 ...
  • 某些线程执行后台任务,例如发送keepalive数据包,或执行定期垃圾收集,或任何。 这些仅在主程序运行时有用,并且一旦其他非守护程序线程退出就可以将其关闭。 没有守护进程的线程,你必须跟踪它们,并告诉他们退出,然后你的程序才能完全退出。 通过将它们设置为守护进程线程,您可以让它们运行并忘记它们,并且当程序退出时,任何守护程序线程将自动被杀死。 Some threads do background tasks, like sending keepalive packets, or performing pe ...
  • func4和所有其他的线程函数一样,只要函数返回就会导致线程死掉,所以没什么特别的要求。 但是,如果func3会多次调用func4,那么为每个调用启动一个新线程可能效率不高。 特别是如果您想以功能样式编写代码,最好使用ThreadPoolExecutor等更高级别的API来调度您的调用。 这也给你一个干净的方式来检索每个调用的返回值,适当时使用result或add_done_callback方法。 After much searching and investigation I was able to fi ...
  • 简短的回答是:没关系。 重要的是,所有守护进程都有一个像init这样的父进程,通过调用wait()可以在子进程死亡时收获它们。 否则,该过程将在退出时变为僵尸 。 将父PID设置为1并没有什么特别之处。您链接到的手册页说这个过程对于旧的SysV风格的守护进程是PID 1,但对于新的SystemD风格的守护进程没有这样说。 init始终作为PID 1运行,传统上它是守护进程的父进程。 但它不需要如此。 systemd --user管理用户服务。 因此,当您运行它(作为用户)时,此进程成为您的守护进程的父进程是 ...
  • 守护程序线程的重点是,如果它在主线程完成时尚未完成,则会被即时终止。 引用文档 : 线程可以标记为“守护程序线程”。 这个标志的意义在于当只剩下守护进程线程时整个Python程序退出。 初始值继承自创建线程。 可以通过守护程序属性或守护程序构造函数参数设置该标志。 注意守护程序线程在关闭时突然停止。 他们的资源(例如打开文件,数据库事务等)可能无法正确发布。 如果您希望线程正常停止,请将它们设置为非守护进程并使用合适的信号机制(如Event)。 现在,看看你的逻辑。 主线程仅在启动线程5后休眠3秒。但是线程 ...
  • 你应该调用t.start() ,而不是t.run() 。 第一个将生成一个新线程并从那里调用自己run 。 调用自己运行会导致您在当前线程中执行a函数。 You should call t.start(), not t.run(). The first one will spawn a new thread and call run itself from there. Calling run on your own causes you to execute the a function in your ...
  • 从threading文档 :“当没有活着的非守护程序线程时,整个Python程序退出”。 守护程序线程将在申请完成后终止。 为了在python中实现系统守护进程,你应该使用os.fork 。 看一下简单守护进程的例子 。 From threading documentation: "The entire Python program exits when no alive non-daemon threads are left". Daemon thread will just be terminated ...
  • 是的,默认情况下,从守护程序线程创建的任何线程也是守护程序线程。 在任何情况下,您都可以使用isDaemon()轻松地对此进行测试。 Yes, by default, any thread created from a daemon thread is also a daemon thread. In any case, you can always test this, very easily - with isDaemon().
  • 在Java中,Daemon和非守护程序线程优先级之间的优先级没有区别,您可以定义优先级,或者它将从父级继承 来自JavaDoc: 新创建的线程的优先级设置为等于创建它的线程的优先级,即当前运行的线程 Oracle Java Doc No there is no difference in priority between Daemon and non-daemon thread priority in Java, you can define priority or it will be inherited ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。