AWS Doc SDK ExamplesWord
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
안녕하세요 AWS Batch
다음 코드 예제에서는 AWS Batch를 사용하여 시작하는 방법을 보여 줍니다.
- Java
-
- Java 2.x용 SDK
-
참고
더 많은 on GitHub가 있습니다. AWS 코드 예시 리포지토리
에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요. import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.core.retry.RetryPolicy; import software.amazon.awssdk.http.async.SdkAsyncHttpClient; import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.batch.BatchAsyncClient; import software.amazon.awssdk.services.batch.model.JobStatus; import software.amazon.awssdk.services.batch.model.JobSummary; import software.amazon.awssdk.services.batch.model.ListJobsRequest; import software.amazon.awssdk.services.batch.paginators.ListJobsPublisher; import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; public class HelloBatch { private static BatchAsyncClient batchClient; public static void main(String[] args) { List<JobSummary> jobs = listJobs("my-job-queue"); jobs.forEach(job -> System.out.printf("Job ID: %s, Job Name: %s, Job Status: %s%n", job.jobId(), job.jobName(), job.status()) ); } public static List<JobSummary> listJobs(String jobQueue) { if (jobQueue == null || jobQueue.isEmpty()) { throw new IllegalArgumentException("Job queue cannot be null or empty"); } ListJobsRequest listJobsRequest = ListJobsRequest.builder() .jobQueue(jobQueue) .jobStatus(JobStatus.SUCCEEDED) .build(); List<JobSummary> jobSummaries = new ArrayList<>(); ListJobsPublisher listJobsPaginator = getAsyncClient().listJobsPaginator(listJobsRequest); CompletableFuture<Void> future = listJobsPaginator.subscribe(response -> { jobSummaries.addAll(response.jobSummaryList()); }); future.join(); return jobSummaries; } private static BatchAsyncClient getAsyncClient() { SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder() .maxConcurrency(100) // Increase max concurrency to handle more simultaneous connections. .connectionTimeout(Duration.ofSeconds(60)) // Set the connection timeout. .readTimeout(Duration.ofSeconds(60)) // Set the read timeout. .writeTimeout(Duration.ofSeconds(60)) // Set the write timeout. .build(); ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() .apiCallTimeout(Duration.ofMinutes(2)) // Set the overall API call timeout. .apiCallAttemptTimeout(Duration.ofSeconds(90)) // Set the individual call attempt timeout. .retryPolicy(RetryPolicy.builder() // Add a retry policy to handle transient errors. .numRetries(3) // Number of retry attempts. .build()) .build(); if (batchClient == null) { batchClient = BatchAsyncClient.builder() .region(Region.US_EAST_1) .httpClient(httpClient) .overrideConfiguration(overrideConfig) .build(); } return batchClient; } }
-
API 세부 정보는 listJobsPaginator AWS SDK for Java 2.x 참조의 API를 참조하세요.
-
기본 사항
작업