小编Wei*_*Sun的帖子

有什么方法可以在 SDK for java 中使用 OutputStream 将对象写入 amazon s3 吗?

我想将一个可序列化的对象写入亚马逊 s3 的桶中。但是,即使我可以使用 S3ObjectInputStream,我也找不到名为 S3ObjectOutputStream 的类。

当然,我可以将可序列化的对象写入本地目录,然后将文件上传到 s3,但我只是想知道有什么方法可以直接使用 OutputStream 写入 amazon s3?

java amazon-s3

6
推荐指数
1
解决办法
2367
查看次数

为什么将 Thread.currentThread().isInterrupted() 与 try/catch 一起使用

我发现这种结构在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 multithreading

5
推荐指数
1
解决办法
1514
查看次数

ExecutorService会阻止它所处的方法吗?

我是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()吗?

java

0
推荐指数
2
解决办法
101
查看次数

标签 统计

java ×3

amazon-s3 ×1

multithreading ×1