首页 > 其他分享 >jdk1.8 AudioSystem 无法关闭流的问题

jdk1.8 AudioSystem 无法关闭流的问题

时间:2023-08-26 21:22:05浏览次数:57  
标签:jdk1.8 fileStream AudioSystem try 关闭 stackoverflow resources

问题

首先说明 JDK 版本,Eclipse Temurin 1.8.0_382,写音频处理时遇到一个文件流无法关闭的问题。具体是javax.sound.sampled.AudioSystem#getAudioInputStream(java.io.File) 写在 try-with-resources 里,在 try-with-resources 结束的代码块外删除文件显示文件被占用,最后在 stackoverflow 找到了答案:audioinputstream close not releasing resources properly is there a workaround

其他

去稍微新一点的 jdk17 看了下这个方法的实现,发现方法变成 stackoverflow 的样子了:

final InputStream fileStream = new FileInputStream(file);
try {
    return getAudioInputStream(new BufferedInputStream(fileStream));
} catch (final Throwable e) {
    closeSilently(fileStream);
    throw e;
}

JDK8 不修复这个问题是有什么原因吗?有点好奇,再贴上 jdk bugs audioInputStream.close() does not release the resource,以后有时间再研究研究为什么 jdk8 无法释放资源

最后

尽早升级 jdk 吧

标签:jdk1.8,fileStream,AudioSystem,try,关闭,stackoverflow,resources
From: https://www.cnblogs.com/hligy/p/17659473.html

相关文章

  • 改造版:moviepy使用ffmpeg按照长度分割mp4,根据源文件命名,及时关闭文件避免异常
    importos#导入os模块,用于处理文件和目录操作importsubprocess#导入subprocess模块,用于在新的进程中执行子程序importtime#导入time模块,用于处理时间相关操作importrandomfrommoviepy.editorimportVideoFileClip#从moviepy.editor模块导入VideoFileCl......
  • ping 收不到pong 关闭连接
    pkg\sky_engine\lib\_http\websocket.dart ///Apingmessageissentevery[pingInterval],startingatthefirst///[pingInterval]afteranewvaluehasbeenassignedorapongmessagehas///beenreceived.Ifapingmessageisnotansweredbyapong......
  • 【MySQL 8.0】在线开启与关闭GTID复制
    在线开启GTID复制(root@node01)>setglobalenforce_gtid_consistency=warn;QueryOK,0rowsaffected(0.04sec)(root@node02)>setglobalenforce_gtid_consistency=warn;QueryOK,0rowsaffected(0.07sec)(root@node01)>setglobalenf......
  • vscode reference代码提示怎么关闭
     ......
  • ci框架关闭notice消息提示方法
    ci框架关闭notice消息提示方法:error_reporting(E_ALL^E_NOTICE);//在控制器加上这句即可最好办法在入口文件if(defined('ENVIRONMENT')){switch(ENVIRONMENT){case'development'://error_reporting(E_ALL);/......
  • android studio启动时关闭上次打开的项目
    每次androidstudio启动就会自动打开上次关闭的项目然后电脑有时候会很卡解决办法:......
  • android studio关闭启动时indexing
    这是个插件,googleappindexing,在setting中搜索到它,关闭就ok了。我是在androidstudio2.1验证的这是个插件,googleappindexing,在setting中搜索到它,关闭就ok了。我是在androidstudio2.1验证的......
  • 1、oracle监听器服务的开启与关闭
    目录oracle监听器服务的开启与关闭1、查看监听状态2、开启监听3、关闭监听4、重启监听oracle监听器服务的开启与关闭Oracle监听器服务关闭时,不让外部进行数据库连接。1、查看监听状态lsnrctlstatus2、开启监听lsnrctlstart3、关闭监听lsnrctlstop4、重启监听lsnrc......
  • JDK1.8使用sonarqube踩坑
    最近在公司使用sonarqube来扫描Java代码,并使用插件;网上的资料缺少这一块的,总结一下:环境信息JDK1.8;sonarqube7.8;(只能用这个版本)插件:使用了阿里的p3c和findbugs4.0.0;这些版本很重要,谁踩坑最多的地方;踩坑网上都说findbug要用3.10,我用了,但报错搞了我好几天报错:org.sonarsource.sc......
  • 控制 打开和关闭远程推送通知
    首先初始化一个switch,如下:我是在cell里面创建的,然后实现switch的方法:这里的话,通过判断switch的状态,yes或是no来控制关闭的,因为app首次运行的话,是有一个注册通知的提示框,点击好以后,就可以接受到apns的推送服务了,如果用户点击不允许的话,是不能接收到推送的!切记!注意这里面的状态判断:1,......