Açıklaması şöyle
According to the description from the Jakarta Batch (JBatch) official website, the JBatch specification provides the following:The Jakarta Batch project describes the XML-based job specification language (JSL), Java programming model, and runtime environment for batch applications for the Java platform.The specification ties together the Java API and the JSL (XML) allowing a job designer to compose a job in XML from Java application artifacts and conveniently parameterize them with values for an individual job. This structure promotes application reuse of artifacts across different jobs.The specification allows the flexibility for batch jobs to be scheduled or orchestrated in any number of ways, and stops short of defining any APIs or constructs regarding scheduling or orchestration of multiple or repeated jobs.
Açıklaması şöyle. Eğer Jakarta EE container kullanmak istemiyorsak, IBM Helidon kullanılabilir.
AbstractBatchlet SınıfıThe usage of JBatch is really vast. Practically everywhere in the enterprise (EE) world there are millions of batch jobs running on millions of servers. The JBatch spec was created to make these types of tasks portable across the enterprise solutions in the Java/Jakarta EE world.And yes, this is just a specification and not a complete implementation — every vendor has to provide its own implementation, but the specification itself is not standalone. It is very specific and depends heavily on other specs, like JTA and JPA, for example. This means if you want to run JBatch jobs, then you need an Enterprise Server that supports full EE spec.
Bir step'i temsil eder
Örnek
Şöyle yaparız
import javax.batch.api.AbstractBatchlet;import javax.inject.Named;@Namedpublic class MyBatchlet extends AbstractBatchlet {@Overridepublic String process() {System.out.println("Running inside a batchlet");return "COMPLETED";}}
AbstractItemReader Sınıfı
Örnek
Şöyle yaparız
import javax.batch.api.chunk.AbstractItemReader; import javax.inject.Named; public class MyInputRecord { ... } @Named public class MyItemReader extends AbstractItemReader { private final StringTokenizer tokens; public MyItemReader() { tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); } @Override public MyInputRecord readItem() { if (tokens.hasMoreTokens()) { return new MyInputRecord(Integer.valueOf(tokens.nextToken())); } return null; } }
Örnek
Şöyle yaparız
import javax.batch.api.chunk.ItemProcessor; import javax.inject.Named; public class MyOutputRecord { ... } @Named public class MyItemProcessor implements ItemProcessor { @Override public MyOutputRecord processItem(Object t) { System.out.println("processItem: " + t); MyInputRecord record = (MyInputRecord) t; return record.getId() % 2 == 0) ? null : new MyOutputRecord(record.getId() * 2); } }
AbstractItemWriter Sınıfı
Örnek
Şöyle yaparız
import javax.batch.api.chunk.AbstractItemWriter; import javax.inject.Named; @Named public class MyItemWriter extends AbstractItemWriter { @Override public void writeItems(List list) { System.out.println("writeItems: " + list); } }
Hiç yorum yok:
Yorum Gönder