您好,登录后才能下订单哦!
一、编程规约
l 阿里的P3C开发规范插件会给出警告:
private static ExecutorService executor = Executors.newFixedThreadPool(4);
l Java多线程异步音频播放器:
实现Java音频播放器时,支持多线程异步播放,创建线程池时遵守《阿里Java开发手册》规约。
代码下载:https://github.com/rickding/HelloJava/tree/master/HelloAudio
class Player implements Runnable {
private static ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(
4,
new BasicThreadFactory.Builder().namingPattern("audio-player-pool-%d").daemon(true).build()
);
public static void asyncPlay(URL fileUrl) {
if (fileUrl == null) {
return;
}
// 播放进程
Player player = new Player();
try {
player.audioStream = AudioSystem.getAudioInputStream(fileUrl);
} catch (UnsupportedAudioFileException e) {
System.err.println(e.getMessage());
} catch (IOException e) {
System.err.println(e.getMessage());
}
executorService.execute(player);
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。