如何允许用户轻松选择Java Swing应用程序中要分配的内存量? [英] How do I allow the user to easily choose how much memory to allocate in a Java Swing app?

查看:120
本文介绍了如何允许用户轻松选择Java Swing应用程序中要分配的内存量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Swing应用程序,可以处理相对大量的数据.例如,我们目前正在处理具有数百万行数据的CSV文件.出于性能和简便性的原因,我们只将所有数据保留在内存中.但是,不同的用户将需要处理的数据量也不同,RAM数也将不同.当然,在创建安装程序时,我们需要指定堆大小.有什么简单的方法可以允许用户指定堆,而无需他们手动编辑配置或.bat文件?我猜不是所有的用户都会对此感到满意.

We have a Swing app that processes relatively large amounts of data. For instance we currently process CSV files with millions of rows of data. For the reasons of performance and simplicity we just keep all of the data in memory. However different users will have different amounts of data they need to process as well as different amounts of RAM. When creating the installer, of course we need to specify the heap size. Is there any easy way to allow the user to specify the heap without them needing to hand edit a configuration or .bat file? I'm guessing not all users would be comfortable with this.

我看过一个示例,其中一个应用程序指定了三个不同的快捷方式,每个快捷方式都指定了不同的内存量.这可以工作,但我想选择一个更灵活的选项.然后,用户可以选择最适合他们的一种.

I've seen one example where an app specified three different shortcuts each with a different amount of memory specified. This could work but I would like an option that is more flexible. The user could then just choose the one that would work best for them.

推荐答案

我建议使用类似于IntelliJ的东西.当发生OutOfMemoryException时,它会弹出一个配置对话框.该对话框允许用户配置堆大小并将其存储到idea.exe.vmoptions.您需要将文件的内容包含在java/javaw启动命令中,或者具有一个Java程序引导程序,然后启动真正的引导程序.

I recommend having something similar to IntelliJ. It brings up a configuration dialog when an OutOfMemoryException occurs. This dialog allows the user to configure the heap size and stores it to idea.exe.vmoptions. You would need to sub the contents of the file into the java/javaw launch command or have one Java program bootstrap and launch the real one.

一个很酷的变体是根据数据大小建议内存大小.用户确实无法知道程序需要多少内存,因此您可以在选择值时提供任何指导,这将极大地帮助他们.

A really cool variant on this is to suggest a memory size based on the data size. The user really has no way of knowing how much memory your program needs so any guidance you can provide in selecting the value will help them immensely.

在支持该解决方案方面,期望并以避免数据损坏的方式处理OutOfMemoryExceptions非常重要!

It is extremely important in support of this solution that you expect and handle OutOfMemoryExceptions in a way that avoids data corruption!

这篇关于如何允许用户轻松选择Java Swing应用程序中要分配的内存量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆