久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Java 中的 File.exists 有多貴

How expensive is File.exists in Java(Java 中的 File.exists 有多貴)
本文介紹了Java 中的 File.exists 有多貴的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想知道 File.exists() 是如何工作的.我不太了解文件系統的工作原理,所以我應該先從那里開始閱讀.

I am wondering how File.exists() works. I'm not very aware of how filesystems work, so I should maybe start reading there first.

但對于快速的預信息:

調用 File.exists() 是否是文件系統的單個操作,如果該路徑和文件名已在某個日志中注冊?還是操作系統獲取目錄的內容,然后掃描它以查找匹配項?

Is a call to File.exists() a single action for the filesystem, if that path and filename are registered in some journal? Or does the OS get the content of the directory and then scan through it for matches?

我認為這將取決于文件系統,但也許所有文件系統都使用快速方法?

I presume this will be filesystem dependant, but maybe all filesystems use the quick approach?

我不是在談論網絡和磁帶系統.讓我們把它保存到 ntfs、extX、zfs、jfs :-)

I'm not talking about network and tape systems. Lets keep it to ntfs, extX, zfs, jfs :-)

推薦答案

如果第一次執行此操作完全取決于文件系統.這是由操作系統完成的,Java 沒有任何作用.

How this operation if performed the first time is entirely dependant on the filesystem. This is done by the OS and Java doesn't play any part.

就性能而言,在所有情況下都需要讀取磁盤.這通常需要 8-12 毫秒.@Sven 指出一些存儲可能會變慢,但在性能很重要的情況下這種情況相對較少.如果這是一個網絡文件系統,您可能會有額外的延遲(通常相對較小,但取決于您的網絡延遲).

In terms of performance, a read to a disk is required in all cases. This typically takes 8-12 ms. @Sven points out some storage could slower, but this relatively rare in cases where performance is important. You may have an additional delay if this is a network file system (usually relatively small but it depends on your network latency).

相比之下,操作系統和 Java 所做的一切都非常短.

Everything else the OS and Java does is very short by comparison.

但是,如果您反復檢查文件是否存在,則可能不需要磁盤訪問,因為可以緩存信息,在這種情況下是操作系統占用的時間和資源.File.exists() 創建的這些對象中最大的一個(您不會認為它會創建),但是它會在每次調用創建大量對象時對文件名進行編碼.如果你把 File.exists() 放在一個緊密的循環中,它每秒會產生 400MB 的垃圾.:(

However, if you check the file exists repeatedly, a Disk access may not be required as the information can cached, in this case the time the OS takes and resources. One of the largest of these the objects File.exists() creates (you wouldn't think it would) however it encodes the file's name on every call creating a lot of objects. If you put File.exists() in a tight loop it can create 400MB of garbage per second. :(

通過跟蹤您對文件系統所做的所有更改,日志文件系統的工作方式有所不同,但它們不會改變您讀取文件系統的方式.

Journaling filesystems work differently by keeping track of all the changes you make to a file system, however they don't change how you read the filesystem.

這篇關于Java 中的 File.exists 有多貴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 久久久久亚洲精品中文字幕 | 91精品国产综合久久婷婷香蕉 | 婷婷中文在线 | 久久国产免费看 | 1204国产成人精品视频 | 一区二区av| 亚洲首页| 综合久久久久 | 亚洲国产一区二区三区在线观看 | 在线欧美亚洲 | 色婷婷影院 | 日韩在线资源 | 亚洲高清视频一区二区 | 香蕉久久久 | 人妖无码 | 99久久精品免费看国产四区 | 天天干天天插天天 | 一级毛片视频在线 | 91最新视频 | 99riav3国产精品视频 | 91久久久久久久久 | 国产农村妇女精品一二区 | 第一色在线 | 一级黄色录像片子 | 国产最好的av国产大片 | 国产日韩欧美在线 | 欧美三级视频在线观看 | 三级视频在线观看 | 久久久综合久久 | 日韩美香港a一级毛片免费 国产综合av | 精品视频www| 亚洲精品无人区 | 亚洲精品一区二区网址 | 国产网站在线免费观看 | 国产日韩视频 | 久久视频精品 | 日日天天| 91精品久久久久久久久 | 国产中文一区二区三区 | 中国大陆高清aⅴ毛片 | 日韩一区二区三区在线 |