小编joh*_*ohn的帖子

AWS Lambda 是否优于 AWS Glue Job?

在AWS Glue作业中,我们可以编写一些脚本并通过作业执行脚本。

在 AWS Lambda 中,我们也可以编写相同的脚本并执行上述作业中提供的相同逻辑。

因此,我的疑问不是 AWS Glue Job 与 AWS Lambda 之间有什么区别,而是我试图了解 AWS Glue 作业何时应优先于 AWS Lambda,特别是当两者执行相同的作业时?如果两者执行相同的工作,那么理想情况下我会盲目地更喜欢使用 AWS Lambda 本身,对吧?

请尝试理解我的查询..

amazon-web-services aws-lambda aws-glue

34
推荐指数
2
解决办法
3万
查看次数

为什么我们不能使用RuntimeException而不是创建自定义异常?

1)我一直在寻找什么时候才应该创建自定义异常。我发现了这个例子:

public class IncorrectFileExtensionException extends Exception {
    public IncorrectFileExtensionException () {

    }

    public IncorrectFileExtensionException (String message) {
        super (message);
    }

    public IncorrectFileExtensionException (Throwable cause) {
        super (cause);
    }

    public IncorrectFileExtensionException (String message, Throwable cause) {
        super (message, cause);
    }
}
Run Code Online (Sandbox Code Playgroud)

提供上述自定义异常的真正价值是什么?除了创建上面的自定义异常外,我为什么不能抛出新的RuntimeException(“发生错误”,e)?我已经在互联网上看到许多创建类似的自定义异常的示例,但是我不明白上述方法的真正好处是什么。

如果我们创建类似IncorrectFileExtensionException的项目,那么我们的项目最终会出现许多自定义异常。

2)我也发现了这一点:

public class MyUncheckedBusinessException extends RuntimeException {

    private static final long serialVersionUID = -8460356990632230194L;

    private final ErrorCode code;

    public MyUncheckedBusinessException(ErrorCode code) {
        super();
        this.code = code;
    }

    public MyUncheckedBusinessException(String message, Throwable cause, …
Run Code Online (Sandbox Code Playgroud)

java exception

5
推荐指数
2
解决办法
155
查看次数

为什么java8流消费者andThen方法?

我是 Java 8 的新手,只是想问一下下面两个代码片段在性能上有什么区别。

我知道这两种方法都有效,但我想知道为什么 Java 团队Consumer::andThen在我可以使用正常方法时创建了方法。

List<String> list = Arrays.asList("aaa","cccc","bbbb");
List<String> list2 = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

//方法一

list.stream().forEach(x -> {
            list2.add(x);
            System.out.println(x);
        });
Run Code Online (Sandbox Code Playgroud)

//方法二

Consumer<String> c1 = s -> list2.add(s);
Consumer<String> c2 = s -> System.out.println(s);

list.stream().forEach(c1.andThen(c2));
Run Code Online (Sandbox Code Playgroud)

IMO,方法 1更好,为什么又是方法 2?如果两者相同,那么为什么要创建andThen()方法?我想一定有他们创造的原因。

换句话说,该andThen()方法究竟何时真正有用?

java java-8 java-stream

4
推荐指数
1
解决办法
783
查看次数

@RestController @GetMapping 没有处理程序问题的适配器

学习Spring Rest,有以下疑问:

@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/test")    
    public int testTransaction(){
        return 10;
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码段效果很好,并返回了响应 10。

@RestController("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping 
    public int testTransaction(){
        return 10;
    }
}
Run Code Online (Sandbox Code Playgroud)

对于上面的片段,给我一个错误如下:

 threw exception No adapter for handler The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler with root cause
Run Code Online (Sandbox Code Playgroud)

任何的想法?可能是什么原因..?我认为两者都应该有效,但上面的一个不起作用......

rest spring spring-mvc spring-boot spring-rest

2
推荐指数
1
解决办法
1244
查看次数

如果发生任何故障,Saga 模式是否能够帮助逆转支出?

我对传奇模式很陌生。我明白了,在Saga的帮助下,如果出现任何故障,我们都可以扭转局面。

无论我见过什么例子,它们大多都是像Orders Service -> Payment Service -> Other Service,在 Payment service 中,资金是从 Customer 到 Merchant 发生的如果其他 Service 发生任何故障,这个支付交易可以是能够逆转,因为这里资金从商家流向客户(在逆转失败过程中)

但是,我的查询是:我有一个像这样的反向场景:付款服务 -> 客户服务

支付服务中,资金从商户流向客户

如果客户服务出现任何故障,我们是否可以使用 Saga 逆转付款交易?(即,将资金从客户转回商家,以防发生任何故障)

以上可以使用Saga吗?希望我的疑问很清楚。如果有人能够在上述方面帮助我,我会很高兴。

design-patterns cqrs event-sourcing saga microservices

2
推荐指数
1
解决办法
742
查看次数

StringBuilder 子字符串错误行为

public class Demo234234 {

    public static void main(String[] args) {
        
        String s = "aa";
        StringBuilder sb = new StringBuilder(s);
        System.out.println(sb);
        
        sb.append("bb");
        System.out.println(sb);
        
        sb.substring(s.length());
        System.out.println(sb); // Here I expected as "bb", but getting "aabb", why?
        System.out.println(sb.substring(s.length()));
        
    }

}
Run Code Online (Sandbox Code Playgroud)

输出:

aa
aabb
aabb
bb
Run Code Online (Sandbox Code Playgroud)

我期望该行的输出为“bb” System.out.println(sb);,但结果却为“aabb”,可能知道为什么吗?

sb.append("bb");行为正确,那为什么不呢sb.substring(s.length());

还有一件事要问:哪个更好用?stringObj.substring() 还是 stringBuilder.substring() ??

java

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