执行线程1; 线程名称:main 执行线程1; 线程名称:main 执行线程2; 线程名称:Thread-1 Exception in thread "main" java.lang.IllegalThreadStateException at java.lang.Thread.start(Thread.java:708) at com.example.springbatchdemo.job.Test.main(Test.java:29)
publicsynchronizedvoidstart(){ /** * This method is not invoked for the main method thread or "system" * group threads created/set up by the VM. Any new functionality added * to this method in the future may have to also be added to the VM. * * A zero status value corresponds to state "NEW". */ if (threadStatus != 0) thrownew IllegalThreadStateException();
Spring 容器是 Spring 框架的核心。容器负责配置对象,注入对象,管理对象,并完成整个生命周期。Spring 容器依赖控制反转(Inversion of Control),也即依赖注入(Dependency Injection)来配置并注入对象。这样的对象被成为 Bean。具体过程可抽象为:Spring 读取程序中的 Bean 配置信息,并据此在容器中生成一份 Bean 配置注册表,然后再根据注册表实例化 Bean ,装配好待用。
Spring 提供了两种容器:BeanFactory 与 ApplicationContext。BeanFactory 为 Spring Ioc 功能提供了底层的实现基础,但为了实现框架化,Spring 新增了ApplicationContext 接口。 ApplicationContext 继承于 BeanFactory,并涵盖其所有功能。官方对两个容器做出比较:
// 属性组 private MimeHeaderField[] headers = new MimeHeaderField[8];
/** * Allow "set" operations, which removes all current values * for this header. * @param name The header name * @return the message bytes container for the value */ public MessageBytes setValue(String name){ for(int i = 0; i < this.count; ++i) { if (this.headers[i].getName().equalsIgnoreCase(name)) { for(int j = i + 1; j < this.count; ++j) { if (this.headers[j].getName().equalsIgnoreCase(name)) { this.removeHeader(j--); } } returnthis.headers[i].getValue(); } } MimeHeaderField mh = this.createHeader(); mh.getName().setString(name); return mh.getValue(); }