Java 应用程序在用户闲置 10 分钟后导致屏幕显示无响应

发布于 2024-08-20 11:47:19 字数 1657 浏览 9 评论 0原文

我编写了一个Java应用程序,允许用户编写鼠标/键盘输入脚本(JMacro,链接不重要,仅适用于好奇的)。我个人使用该应用程序在夜间睡觉时自动执行在线游戏中的角色动作。不幸的是,我早上总是回到电脑前,发现它没有反应。经过进一步测试,我发现我的应用程序会导致计算机在大约 10 分钟的用户空闲时间后变得无响应(即使应用程序本身模拟用户活动)。我似乎无法确定问题所在,所以我希望其他人可以建议在哪里查看或可能导致问题的原因。

相关症状和特征:

  • 用户闲置 10 分钟后出现无响应
  • 用户仍然可以在屏幕上移动鼠标指针 除了
  • 鼠标之外的所有内容都显示为冻结...鼠标单击没有效果并且应用程序没有更新他们的显示器,包括 Windows 7 桌面
  • 我将任务管理器与应用程序一起保留了一夜,这样我就可以在屏幕冻结之前看到最后一个任务管理器图像...Java 应用程序处于正常的 CPU/内存使用率和总 CPU 使用率只有~1%
  • 移动鼠标后(换句话说,用户从闲置中回来),屏幕图像在 30 分钟内再次开始更新(这是非常偶然的...有时 10 分钟,有时之后没有结果两个小时)
  • 用户可以通过 CTRL-ALT-DEL 进入 Windows 7 的 CTRL-ALT-DEL 屏幕(暂停 30 秒后)。用户仍然可以移动鼠标指针,但单击任何按钮选项都会导致屏幕再次冻结
  • 在某些非常罕见的情况下,系统永远不会冻结,并且我在早上以完全响应速度返回
  • Java 应用程序在半夜自动停止输入脚本,因此 Windows 7 检测到“真正的”闲置状态并将显示器转入待机模式……在我早上醒来时手动移动鼠标,它们成功地退出了待机模式,尽管桌面显示仍然冻结

鉴于问题的症状和特征,就好像 Java 应用程序导致登录用户的桌面显示停止更新,包括任何正在运行的应用程序。

使用的编程概念和 Java 包:

  • 多线程
  • 标准 outerr 被重新路由到 javax.swing.JTextArea
  • 应用程序使用 Swing GUI
  • awt.Robot(非常频繁使用)
  • awt.PointerInfo
  • awt.MouseInfo

系统规格:

  • Windows 7 Professional
  • Java 1.6.0 u17

总之,我应该强调,我并不是在寻找任何特定的解决方案,因为我不是在问一个非常具体的问题。我只是想知道是否有人在使用我正在使用的 Java 库时遇到过类似的问题。我也很乐意感谢任何建议,以尝试进一步查明导致我的问题的原因。

谢谢!

罗斯

PS,如果我在继续调试此问题时遇到其他任何问题,我将发布更新/答案。

更新:我的应用程序涉及多线程进程,每个进程初始化自己的机器人对象并异步创建输入事件。我重构了该应用程序,使其仅包含一个 Robot 单例对象,但不同的进程仍然异步调用输入命令。据我所知,这并没有改变我的应用程序的行为。我的下一步可能是围绕机器人单例创建一个同步包装器,看看这是否有帮助,但鉴于症状,我不知道为什么会这样。

I've written a Java app that allows users to script mouse/keyboard input (JMacro, link not important, only for the curious). I personally use the application to automate character actions in an online game overnight while I sleep. Unfortunately, I keep coming back to the computer in the morning to find it unresponsive. Upon further testing, I'm finding that my application causes the computer to become unresponsive after about 10 minutes of user idle time (even if the application itself it simulating user activity). I can't seem to pin-point the issue, so I'm hoping somebody else might have a suggestion of where to look or what might be causing the issue.

The relevant symptoms and characteristics:

  • Unresponsiveness occurs after user is idle for 10 minutes
  • User can still move the mouse pointer around the screen
  • Everything but the mouse appears frozen... mouse clicks have no effect and no applications update their displays, including the Windows 7 desktop
  • I left the task manager up along the with the app overnight so I could see the last task manager image before the screen freezes... the Java app is at normal CPU/Memory usage and total CPU usage is only ~1%
  • After moving the mouse (in other words, the user comes back from being idle), the screen image starts updating again within 30 minutes (this is very hit and miss... sometimes 10 minutes, sometimes no results after two hours)
  • User can CTRL-ALT-DEL to get to Windows 7's CTRL-ALT-DEL screen (after a 30 second pause). User is still able to move mouse pointer, but clicking any of the button options causes the screen to appear to freeze again
  • On some very rare occasions, the system never freezes, and I come back to it in the morning with full responsiveness
  • The Java app automatically stops input scripting in the middle of the night, so Windows 7 detects "real" idleness and turns the monitors into Standby mode... which they successfully come out of upon manually moving the mouse in the morning when I wake up, even though the desktop display still appears frozen

Given the symptoms and characteristics of the issue, it's as if the Java app is causing the desktop display of the logged in user to stop updating, including any running applications.

Programming concepts and Java packages used:

  • Multi-threading
  • Standard out and err are rerouted to a javax.swing.JTextArea
  • The application uses a Swing GUI
  • awt.Robot (very heavily used)
  • awt.PointerInfo
  • awt.MouseInfo

System Specs:

  • Windows 7 Professional
  • Java 1.6.0 u17

In conclusion, I should stress that I'm not looking for any specific solutions, as I'm not asking a very specific question. I'm just wondering if anybody has run into a similar problem when using the Java libraries that I'm using. I would also gladly appreciate any suggestions for things to try to attempt to further pinpoint what is causing my problem.

Thanks!

Ross

PS, I'll post an update/answer if I manage to stumble across anything else while I continue to debug this.

Update: my app involved multi-threaded processes each initializing their own Robot objects and creating input events asynchronously. I refactored the app to only contain one Robot singleton object, but the different processes still asynchronously invoke input commands. As far as I can tell, this did not change the behavior of my app. My next step might be to created a synchronized wrapper around the Robot singleton to see if that helps, but given the symptoms, I don't know why it would.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

一笔一画续写前缘 2024-08-27 11:47:19

我之前在使用 Robot 类时遇到过问题。我完全忘记了我做了什么,但它导致计算机锁定并且我被迫重新启动。

I've had problems using the Robot class before. I forget exactly what I've done, but it has caused the computer to lock up and I've been forced to reboot.

尐偏执 2024-08-27 11:47:19

I'm not familiar with the vagaries of Robot, but Uncaught exceptions in GUI applications can produce very odd results as the event dispatch thread dies and restarts. You might get some ideas from How uncaught exceptions are handled.

追我者格杀勿论 2024-08-27 11:47:19

如果您激活任何屏幕保护程序或类似的东西,就会发生这种情况,然后这个机器人动作将停止工作

我通过以下方式遇到了这个问题,

我有一些基于 GUI 的应用程序,并且我编写了一些基于机器人类的测试代码。

但是,如果我在系统中激活了屏幕保护程序,则此测试用例将停止工作...

请检查您的案例中是否存在此类情况

This can happen if u activated any screen saver or some thing like that, then this robot actions will stop working

i got this problem in the following way

i am having some GUI based applications and i written some test code based on Robot class.

but if i activated screen saver in my system this test cases stopped working...

please check any such scenarios are there in your case

半葬歌 2024-08-27 11:47:19

对于Ross,我很确定您遇到了策略问题,这意味着您没有权限并被win7阻止。要获得此许可,您必须创建一项策略,这是一个大故事。检查您可以从 sun 网站获得哪些信息。

对于其他人来说,如果您的程序在一段时间后停止工作,则可能是您没有正确处理程序中的所有异常。尝试在该行停止时获取该行:您可以通过将一行文本发送到系统控制台来完成,然后重写它以获得您想要的性能。

其余的请检查您的代码并检查它,确保您没有陷入死锁,如果您的电脑有问题,那么死锁可能会卡住您的电脑。

还要检查 CPU 使用情况,看看您的程序是否超载,如果超载,您的 CPU 温度控制将自动重新启动或关闭您的电脑。

如果我没有遇到问题,请告诉我;如果您解决了此案,请告诉我您做了什么。

for Ross, I am pretty sure that you have a policy problem which mean that you don't have permission and getting block by win7. To get this permission you must create a policy and that is a big of a story. Check what info you can get from sun website.

For the others if your program stops working after some period of time it might be that you are not handling all of the exception in your program right. Try to get the line when it stops: you can do it by just sending a line of text to the system console, and rewrite it to get the performance you want.

For the rest check your code and check it good very good to see that you are not getting into a dead lock which might stuck your pc if it has something with it.

Also check to see the CPU usage and see if your program is overloading it if it does your CPU temperature control will restart or turn off your PC automatically.

If i didn't hit the problem, let me know; if you solved the case please let me know what you did.

抠脚大汉 2024-08-27 11:47:19

我们有两台机器,其 Java 应用程序的行为几乎完全相同。

一种是 Windows 7 64 位,其中 Eclipse 64 位和 Java 6(64 位)导致完全相同的冻结。

其他情况是 Windows 7 32 位和 Java 应用程序使用大量 CPU 和磁盘活动,导致冻结。

这两台机器都是东芝笔记本电脑,配备现代 CPU(Core 2 Duo)。

此外,两台机器都安装了 NOD32 防病毒软件。

标准应用程序(Office、Skype、Firefox...)

We have two machines with almost exactly same behavior with Java applications.

One is with Windows 7 64 bit, where Eclipse 64bit and Java 6 (64bit) is causing exactly same freeze.

Other is with Windows 7 32 bit and Java application utilizing a lot of CPU and disk activity causing freeze.

Both machines are notebooks from Toshiba with modern CPU's (Core 2 Duo).

Also both machines have NOD32 anti virus installed.

Standard apps (Office, Skype, Firefox,...)

和我恋爱吧 2024-08-27 11:47:19

我们似乎将问题追踪到了 NOD32。当我们禁用 NOD32 时,似乎不再发生该行为。

我想指出的是,我不认为它是 NOD32 本身,而是 Windows 7、Java JDK 和 NOD32 的某种组合。

We seem to tracked down problem to NOD32. When we disable NOD32 it seems that beahaviour does not occure anymore.

I want to point out that I don't think it's NOD32 itself, but some combination of Windows 7, Java JDK and NOD32.

酒解孤独 2024-08-27 11:47:19

我在 Mac OS X 10.6.7 上遇到了类似的问题,但它并没有冻结整个系统,而是冻结了我的应用程序运行的整个 java 进程,并且随机有趣。解决此问题的方法是调用:

Toolkit.getDefaultToolkit();

在创建任何机器人之前,例如:

    public static void main(String[] args) {    
        Toolkit.getDefaultToolkit();
        //Blah blah
    }

Robotinit 方法中进行相同的调用类似乎是问题的根源,这很愚蠢,对我来说没有多大意义,但现在工作得很好:)

I ran into a similar issue on Mac OS X 10.6.7 but it was not freezing entire system but the entire java process where my application was running in, and interesting at random basis. Workaround for this was call:

Toolkit.getDefaultToolkit();

Before create any Robot, in example:

    public static void main(String[] args) {    
        Toolkit.getDefaultToolkit();
        //Blah blah
    }

Same call is made in init method at Robot class so seems where the problems are coming from, this is stupid and does not make a lot sense to me but works perfectly now :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文