Commit a818dd1b by 朱瑞泽

test

parent 69fe1411
......@@ -6,6 +6,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -49,15 +52,36 @@ public class TestRun {
);
}
public static void main(String[] args) throws InterruptedException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-conf.xml");
TestRun bean = applicationContext.getBean(TestRun.class);
DemoStoreService demoStoreService = applicationContext.getBean(DemoStoreService.class);
public void test2(DemoStoreService demoStoreService) {
System.out.println("无事务");
bean.test(demoStoreService::test1);
demoStoreService.test1("123");
System.out.println("开启事务");
bean.test(demoStoreService::test2);
demoStoreService.test2("456");
System.out.println("只读事务");
bean.test(demoStoreService::test3);
demoStoreService.test3("789");
}
public static void main(String[] args) throws InterruptedException, IOException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-conf.xml");
TestRun bean = applicationContext.getBean(TestRun.class);
DemoStoreService demoStoreService = applicationContext.getBean(DemoStoreService.class);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// String s = reader.readLine();
// System.out.println(s);
// System.out.println("无事务");
// bean.test(demoStoreService::test1);
// System.out.println("开启事务");
// bean.test(demoStoreService::test2);
// System.out.println("只读事务");
// bean.test(demoStoreService::test3);
while (true) {
String s2 = reader.readLine();
System.out.println(s2);
if (s2.equals("exit")) {
System.exit(0);
break;
}
bean.test2(demoStoreService);
}
}
}
<?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:context="http://www.springframework.org/schema/context"
xmlns:apollo="http://www.ctrip.com/schema/apollo"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.ctrip.com/schema/apollo
http://www.ctrip.com/schema/apollo.xsd">
<context:annotation-config />
<!--<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />-->
<!--<apollo:config/>-->
<apollo:config namespaces="COMMON.4.0-jdbc"/>
<bean id="dataSource" class="com.gic.commons.datasource.DruidDatasourceWrapper">
<!-- 基本属性 url、user、password -->
<!--<property name="url" value="${jdbc.url}" />-->
<!--<property name="username" value="${jdbc.username}" />-->
<!--<property name="password" value="${jdbc.password}" />-->
<property name="databaseId" value="${jdbc.databaseId}"/>
<property name="schema" value="${jdbc.schema}"/>
<property name="jdbcOptions" value="${jdbc.jdbcOptions}"/>
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="10" />
<property name="minIdle" value="1" />
<property name="maxActive" value="${jdbc.maxsize}" />
<property name="defaultAutoCommit" value="true" />
<property name="removeAbandoned" value="false" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandonedTimeout" value="120" /> <!-- 1800秒,也就是30分钟 -->
<property name="logAbandoned" value="true" /> <!-- 关闭abanded连接时输出错误日志 -->
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="0" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="connectionInitSqls" value="set names utf8mb4;"/>
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 <property name="poolPreparedStatements"
value="false"/> <property name="maxPoolPreparedStatementPerConnectionSize"
value="20"/> -->
<!-- 配置监控统计拦截的filters <property name="filters" value="stat"/> -->
</bean>
<!--<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">-->
<!--&lt;!&ndash; 基本属性 url、user、password &ndash;&gt;-->
<!--<property name="url" value="${jdbc.url}" />-->
<!--<property name="username" value="${jdbc.username}" />-->
<!--<property name="password" value="${jdbc.password}" />-->
<!--&lt;!&ndash; 配置初始化大小、最小、最大 &ndash;&gt;-->
<!--<property name="initialSize" value="10" />-->
<!--<property name="minIdle" value="1" />-->
<!--<property name="maxActive" value="${jdbc.maxsize}" />-->
<!--<property name="removeAbandoned" value="true" /> &lt;!&ndash; 打开removeAbandoned功能 &ndash;&gt;-->
<!--<property name="removeAbandonedTimeout" value="120" /> &lt;!&ndash; 1800秒,也就是30分钟 &ndash;&gt;-->
<!--<property name="logAbandoned" value="true" /> &lt;!&ndash; 关闭abanded连接时输出错误日志 &ndash;&gt;-->
<!--&lt;!&ndash; 配置获取连接等待超时的时间 &ndash;&gt;-->
<!--<property name="maxWait" value="0" />-->
<!--&lt;!&ndash; 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 &ndash;&gt;-->
<!--<property name="timeBetweenEvictionRunsMillis" value="60000" />-->
<!--&lt;!&ndash; 配置一个连接在池中最小生存的时间,单位是毫秒 &ndash;&gt;-->
<!--<property name="minEvictableIdleTimeMillis" value="300000" />-->
<!--<property name="validationQuery" value="SELECT 'x'" />-->
<!--<property name="testWhileIdle" value="true" />-->
<!--<property name="testOnBorrow" value="false" />-->
<!--<property name="testOnReturn" value="false" />-->
<!--&lt;!&ndash; 打开PSCache,并且指定每个连接上PSCache的大小 <property name="poolPreparedStatements" -->
<!--value="false"/> <property name="maxPoolPreparedStatementPerConnectionSize" -->
<!--value="20"/> &ndash;&gt;-->
<!--&lt;!&ndash; 配置监控统计拦截的filters <property name="filters" value="stat"/> &ndash;&gt;-->
<!--</bean>-->
</beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment