您好,登錄后才能下訂單哦!
一、編程規(guī)約
l 阿里的P3C開發(fā)規(guī)范插件會給出警告:
private static ExecutorService executor = Executors.newFixedThreadPool(4);
l Java多線程異步音頻播放器:
實現(xiàn)Java音頻播放器時,支持多線程異步播放,創(chuàng)建線程池時遵守《阿里Java開發(fā)手冊》規(guī)約。
代碼下載: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;
}
// 播放進(jìn)程
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);
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。