小编pra*_*mar的帖子

我收到错误表'test.batch_job_instance'不存在

我是春季批次新手.我已经使用inmemoryrepository配置了我的工作.但似乎仍然使用db来持久工作Metadeta.我的春季批量配置是:

@Configuration公共类BatchConfiguration {

@Autowired
private StepBuilderFactory stepBuilderFactory;

@Autowired
private JobBuilderFactory jobBuilder;

@Bean
public JobLauncher jobLauncher() throws Exception {
    SimpleJobLauncher job =new SimpleJobLauncher();
    job.setJobRepository(getJobRepo());
    job.afterPropertiesSet();
    return job;
}


@Bean
public PlatformTransactionManager getTransactionManager() {
    return new ResourcelessTransactionManager();
}

@Bean
public JobRepository getJobRepo() throws Exception {
    return new MapJobRepositoryFactoryBean(getTransactionManager()).getObject();
}




@Bean
public Step step1(JdbcBatchItemWriter<Person> writer) throws Exception {
    return stepBuilderFactory.get("step1")
        .<Person, Person> chunk(10)
        .reader(reader())
        .processor(processor())
        .writer(writer).repository(getJobRepo())
        .build();
}

 @Bean
public Job job( @Qualifier("step1") Step step1) throws Exception {
    return jobBuilder.get("myJob").start(step1).repository(getJobRepo()).build();
}
Run Code Online (Sandbox Code Playgroud)

}

如何解决上述问题?

spring-batch

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

java-为什么synchronized块没有给出正确的循环结果

我写了一个代码,创建了几个线程并启动它.我使用synchronized block锁定了对象的监视器.我希望创建的第一个线程应该锁定对象并完成其工作.然后任何其他对象都可以输入它.

但它没有发生,程序在下面.

class ThreadCreationDemo implements Runnable
{
    public void run()
    {
        synchronized(this)
        {
            for(int i=0;i<10;i++)
            {   
                System.out.println("i: "+i+" thread: "+Thread.currentThread().getName()+" threadgroup: "+Thread.currentThread().getThreadGroup()+" "+Thread.holdsLock(this));
                try {
                   Thread.sleep(1000);
                }
                catch(Exception e)
                {   
                    System.out.println(e.toString());   
                }           
            }
        }
    }

    public static void main(String args[])
    {
         Thread t[]=new Thread[5];

         for(int i=0;i<5;i++)
         {
             t[i]=new Thread(new ThreadCreationDemo());
             t[i].start();
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望结果应该是这样的.

首先,i = 0到9的所有值都打印在一个线程名称下,如线程0,然后是线程1等.

但输出是这样的:

i: 0 thread: Thread-1
i: 0 thread: Thread-3
i: 0 thread: Thread-2
i: 0 thread: Thread-0
i: 0 thread: Thread-4 …
Run Code Online (Sandbox Code Playgroud)

java multithreading

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

标签 统计

java ×1

multithreading ×1

spring-batch ×1