Java thread goes to sleep when not in focus on OSX

我们两清 提交于 2019-12-05 18:09:44

I suspect that OSX doesn't provide notification of clipboard changes, so Java is doing the best it can by notifying you whenever it gets woken for some other reason.

My suspicion comes from the NSPasteboard docs, the changeCount routine in particular. It says "You can therefore record the change count at the time that you take ownership of the pasteboard and later compare it with the value returned from changeCount to determine whether you still have ownership." No mention of using an event to detect changes.

Seems Keith is right. However, you can do a workaround by sending the application to the background (on *Nix):

java -jar clipboard-1.0.jar &

This opens the Java application in the background and does not need window focus for notifications to fire.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!