我想将一个可序列化的对象写入亚马逊 s3 的桶中。但是,即使我可以使用 S3ObjectInputStream,我也找不到名为 S3ObjectOutputStream 的类。
当然,我可以将可序列化的对象写入本地目录,然后将文件上传到 s3,但我只是想知道有什么方法可以直接使用 OutputStream 写入 amazon s3?
我发现这种结构在Thinking in java的多线程章节中很流行:
public void run(){
try{
while(!Thread.currentThread().isInterrupted()){
// do something blocked like wait(), sleep() or I/O
}
}catch(InterruptedExeption e){
}
}
Run Code Online (Sandbox Code Playgroud)
但是我现在认为 while 循环当且仅当被阻塞或抛出时才会退出wait(),为什么sleep()不使用呢?或者只是因为它是规范的?I/OInterruptedExeptionwhile(true)Thread.currentThread().isInterrupted()
我是Java的新手,我知道我的问题可能很愚蠢......我发现如果不调用ExecutorService.shutdown(),我的主方法将被ExecutorService阻止返回:
class Test{
public static void main(String[] args){
ExecutorService exec = new Executors.newCachedThreadPool();
exec.execute(new Runnable(){
public void run(){
System.out.println("I am running!");
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不会在主线程中返回.我想知道为什么ExecutorService会阻止main方法,它的目的是强制程序员调用shutdown()吗?