Fastest way to create a Java message dialog (swing/awt/other)?

后端 未结 10 842
醉梦人生
醉梦人生 2021-01-17 12:41

I\'m creating a Java application that will do some processing then needs to display a message to give the user feedback.

However, it appears to be incredibly slow -

相关标签:
10条回答
  • 2021-01-17 13:09

    Have you tried running it through a profiler like NetBeans? If there's a bottleneck deep inside the standard library, that's a good way to find it.

    0 讨论(0)
  • 2021-01-17 13:19

    Do you NEED to use java to display the message box? IF the box is coming from outside of your application, then you might want to use something else to generate a dialog.

    To make a native windows app that just shows a message box from a command line string would only take a few hours at most. Most of the common scripting languages should have ways to do it too. here's an example from some guy through javascript via command line:

    http://www.snee.com/bobdc.blog/2009/01/displaying-a-message-box-from.html

    0 讨论(0)
  • 2021-01-17 13:20

    Also it would be a lot faster to create an AWT Window (or maybe a Frame) instead of a JFrame because the latter has to pull in a gazillion of additional class files.

    0 讨论(0)
  • 2021-01-17 13:22

    Since you're interested in speeding this up, and since most of the overhead seems to be JVM startup overhead, check out Nailgun which aims to address slow JVM startup by keeping a JVM running in the background all the time. In your case, after one run the Swing library too will end up being cached (and hopefully after a few more runs JITed too), further reducing the overhead.

    However this approach will lead to increased memory usage due to the background JVM and also cause other problems since it may not be straightforward to determine when to shut it down.

    0 讨论(0)
提交回复
热议问题