如果一个线程通过创建其对象来创建填充不可变类的引用变量,并且在第一个线程完成之前第二次另一个线程启动并创建不可变类的另一个对象,则不可变类的使用不会是线程不安全?创建一个不可变对象也表示所有字段都标记为final ....."如果对新创建的实例的引用从一个线程传递到另一个线程而没有同步,则可能需要确保正确的行为"他们是否正在尝试假设另一个线程可能会将引用变量重新指向不可变类的某个其他对象,那么线程将指向不同的对象而使状态不一致?
我很好奇JVM查找执行程序的所有位置?我更感兴趣的是了解JVM查找类文件的顺序和位置,比如查看java库,扩展库,类路径等任何目录,比如调用java的当前目录?我对JVM行为更感兴趣,而不是类加载器加载类的方式,我知道它有直到root的父委托机制.
如果从编译类保存在文件系统上的目录以及同一目录中的jar文件中执行类,那么JVM是加载两个还是只加载一个?
假设你有一个不安全的线程Vector,如果我们比较它的性能ArrayList,哪一个会更好,为什么?
我有两个问题,
在Spring MVC应用程序中,拥有ContextLoaderListener的目的是什么?
下面是我在web.xml中的条目,所有MVC bean都在servlet-context.xml中定义.所有基于数据库和注释的事务管理都在applicationContext.xml中定义,我在JBoss中使用容器管理事务
如果我将下面突出显示的applicationContext.xml传递给DispatcherServlet,则trasaction管理器工作正常.但我认为我们应该只将Spring MVC上下文信息传递给DispatcherServlet.
如果我删除applicationContext.xml,事务管理器会停止工作吗?我很困惑什么是管理上下文文件的最佳方法?
在web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext.xml
/WEB-INF/config/spring-mail.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/servlet-context.xml
***/WEB-INF/config/applicationContext.xml***
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Run Code Online (Sandbox Code Playgroud)
applicationContext.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- registers all of Spring's standard post-processors for annotation-based configuration -->
<context:annotation-config />
<jee:jndi-lookup id="dataSource" jndi-name="java:OracleDS"/>
<tx:annotation-driven/>
<tx:jta-transaction-manager/>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> …Run Code Online (Sandbox Code Playgroud)