使用Spring Batch并行运行两个作业

时间:2019-03-07 20:26:06

标签: java spring-boot spring-batch

我设置了spring batch,在同一工作中有两个任务正在运行。我希望能够同时在两个不同的作业中分别运行一个任务,但目前还无法进入该状态。我已经在下面描述了到目前为止的内容:

应用类:

private func configurePickerView() {
    let pickerView = UIPickerView()
    pickerView.delegate = self
    pickerView.dataSource = self
    pickerView.selectRow(selectedRow, inComponent: 0, animated: false)
    contentView.addSubview(pickerView)
    pickerView.translatesAutoresizingMaskIntoConstraints = false
    pickerView.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.25).isActive = true
    guard let orderView = orderView else { return }
    pickerView.rightAnchor.constraint(equalTo: orderView.rightAnchor, constant: -20).isActive = true
    pickerView.centerYAnchor.constraint(equalTo: orderView.centerYAnchor).isActive = true
    //let height = getSize(large: 45, medium: 45, small: 45)
    pickerView.heightAnchor.constraint(equalToConstant: 70).isActive = true
}


func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return tipArray.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return tipArray[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    selectedRow = row
    let tipAsInt = switchStatement(row)
    delegate?.reloadData(tipAsInt)
}

private func switchStatement(_ row: Int) -> Int {
    switch row {
    case 0: return Int(round(0 * Double(subTotal)))
    case 1: return Int(round(0.05 * Double(subTotal)))
    case 2: return Int(round(0.1 * Double(subTotal)))
    case 3: return Int(round(0.15 * Double(subTotal)))
    case 4: return Int(round(0.2 * Double(subTotal)))
    default: return Int(round(0.25 * Double(subTotal)))
    }
}

Spring批处理配置类:

package com.example;

import ... 

@SpringBootApplication

public class App implements CommandLineRunner {
    @Autowired
    JobLauncher jobLauncher;

    @Autowired
    Job job;

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        JobParameters params = new JobParametersBuilder()
                .addString("JobID", String.valueOf(System.currentTimeMillis()))
                .toJobParameters();
        jobLauncher.run(job, params);
    }
}

我还有另外两个称为MyTaskOne.java和MyTaskTwo.java的类,它们描述了两个任务。

由于我刚开始使用Spring Batch,所以我无法弄清楚如何运行两个作业,如何让一个作业运行MyTaskOne.java,让第二个类运行MyTaskTwo.java。任何帮助深表感谢。谢谢!

0 个答案:

没有答案