java中的虚拟磁盘空间预留(Virtual disk space reservation in java)

编程入门 行业动态 更新时间:2024-10-24 12:30:02
java中的虚拟磁盘空间预留(Virtual disk space reservation in java)

假设一个多线程应用程序场景,其中每个线程从网络获取一些数据(一个或多个文件),执行一些处理,然后将结果保存在主机的硬盘上。

在这种情况下,总是存在磁盘空间耗尽的可能性,导致意外的服务行为(例如,系统崩溃)。

为了避免这样的情况,如果Java提供了一种保留硬盘空间的方法,那将会很有帮助,但是,如前面的问题所证明的那样 ,这样的选项不可用,即使它是,它也可能导致低效的分配(例如,在解压缩应用程序的情况下,其不事先知道解压缩数据的总大小)。

因此,替代方案可以是“虚拟磁盘空间预留” ,例如通过在存储器中保留可用空间的静态注册表并使每个线程在继续之前从注册表请求容量。

有没有更好的替代方案,或改进这种方法?

是否有任何(最好是开源)Java库实现这样的功能?

Assume a multithreaded application scenario, in which every thread acquires some data (one or more files) from the network, performs some processing and then saves the results on the hard disk of the hosting machine.

In such a scenario, there is always the possibility that the disk space is exhausted, leading to unexpected service behavior (e.g., a system crash).

To avoid a case like that, it would be helpful if Java provided a means of reserving hard disk space, but, as verified in an earlier question, such an option is not available and even if it were, it could lead to inefficient allocation (e.g., in the case of a decompressing application, which does not know beforehand the total size of the decompressed data).

So, an alternative could be to make "virtual disk space reservations", e.g. by keeping in memory a static registry of the free space and having each thread request capacity from the registry before proceeding.

Are there any better alternatives, or improvements to this approach?

Is there any (preferably open source) Java library that implements such functionality?

最满意答案

实现此方法的一种抽象方法可能是使用常量或用户输入的值来确定允许多线程应用程序使用多少磁盘空间,将其另存为变量并使用同步的get和set方法获取允许空间的值为线程分配空间(尽可能需要但不多可用),然后减去总数,以便其他线程可以看到减少的“磁盘空间”,一旦线程完成并删除数据,重新添加值,以便使用的'磁盘空间'可用于其他线程?

编辑:

它可能导致低效分配(例如,在解压缩应用程序的情况下,其事先不知道解压缩数据的总大小)。

如果发生这种情况并且线程'看到'(通过在提取文件时进行常量检查)它已达到“磁盘空间”的限制,则它可以请求更多空间分配(如果可用),或者将其放回队列直到所需的空间已被其他线程释放

An abstract way to implement this might be to use a constant or user inputted value of how much disk space the multi-threaded application is allowed to use, save this as variable and have synchronized get and set methods that will get the value of allowed space, allocate it space for the thread (as much is needed but not more then available), and then minus that from the total so other threads may see a decreased 'disk space' and once a thread has finished and data is deleted re-add the value so the used 'disk space' becomes usable to other threads?

EDIT:

it could lead to inefficient allocation (e.g., in the case of a decompressing application, which does not know beforehand the total size of the decompressed data).

If this occurs and the thread 'sees' (through a constant check while extracting file) that it has reached its limit of 'disk space', it could then request for more space allocation if available, or be put back into a queue until the needed space has been free'd up by other threads

更多推荐

本文发布于:2023-07-25 10:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1260032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:磁盘空间   Virtual   java   reservation   space

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!