123.线程池-Executors默认线程池__

本文演示了一个简单的Java线程池示例,通过`Executors`创建了一个默认的线程池,并使用`submit()`方法提交了两个任务执行。在任务执行完毕后,调用`shutdown()`方法关闭线程池。
package com.itheima.MythoeadPool;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyThreadPoolDemo {
    public static void main(String[] args) throws InterruptedException {
        //创建一个默认的线程池对象,池子中默认是空的,默认可以容纳int类型的最大值
        ExecutorService executorService = Executors.newCachedThreadPool();
        //Excutors创建线程池对象,
        //ExcutorService控制线程池
        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName()+"在执行了");
        });
        //Thread.sleep(2000);
        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName()+"在执行了");
        });
        executorService.shutdown();
    }
}

2025-10-23 19:35:00.005 ERROR 1 --- [pool-9-thread-3] .s.d.s.i.CityWeatherForecastsServiceImpl : 天气数据获取失败 : java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. 2025-10-23 19:35:00.005 INFO 1 --- [pool-9-thread-3] .s.d.s.i.CityWeatherForecastsServiceImpl : 370523天气信息:CityWeatherForecasts(timeType=null, weatherDate=null, province=null, city=null, adcode=null, weather=null, temperature=null, winddirection=null, windpower=null, humidity=null, reporttime=null, createdUser=null, createdAt=null, updatedAt=null) 2025-10-23 19:35:00.006 DEBUG 1 --- [pool-9-thread-3] c.j.s.d.m.C.insert : ==> Preparing: INSERT INTO DD_CITY_WEATHER_FORECASTS VALUES 2025-10-23 19:35:00.010 DEBUG 1 --- [pool-9-thread-3] c.j.s.d.m.C.insert : ==> Parameters: 2025-10-23 19:35:00.011 DEBUG 1 --- [pool-9-thread-3] c.j.s.d.m.C.insert : ==> Parameters: 2025-10-23 19:35:00.012 DEBUG 1 --- [pool-9-thread-3] c.j.s.d.m.C.insert : ==> Parameters: 2025-10-23 19:35:00.018 DEBUG 1 --- [pool-9-thread-3] c.j.s.d.m.C.insert : ==> Parameters: 2025-10-23 19:35:00.025 ERROR 1 --- [pool-9-thread-3] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task org.apache.ibatis.exceptions.PersistenceException: ### Error flushing statements. Cause: org.apache.ibatis.executor.BatchExecutorException: com.juyuansoft.shpms.dispatch.mapper.CityWeatherForecastsMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: ORA-00933: SQL command not properly ended ### Cause: org.apache.ibatis.executor.BatchExecutorException: com.juyuansoft.shpms.dispatch.mapper.CityWeatherForecastsMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: ORA-00933: SQL command not properly ended at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.5.0.jar!/:3.5.0] at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:255) ~[mybatis-3.5.0.jar!/:3.5.0] at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:128) ~[mybatis-plus-extension-3.1.0.jar!/:3.1.0] at com.baomidou.mybatisplus.extension.service.IService.saveBatch(IService.java:58) ~[mybatis-plus-extension-3.1.0.jar!/:3.1.0] at com.juyuansoft.shpms.dispatch.service.impl.CityWeatherForecastsServiceImpl.getCityWeatherForecastsList(CityWeatherForecastsServiceImpl.java:67) ~[classes!/:na] at com.juyuansoft.shpms.dispatch.service.impl.CityWeatherForecastsServiceImpl$$FastClassBySpringCGLIB$$41fd0295.invoke(<generated>) ~[classes!/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.27.jar!/:5.3.27] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.27.jar!/:5.3.27] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.27.jar!/:5.3.27] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.27.jar!/:5.3.27] at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.27.jar!/:5.3.27] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.27.jar!/:5.3.27] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.27.jar!/:5.3.27] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.27.jar!/:5.3.27] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.27.jar!/:5.3.27] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.27.jar!/:5.3.27] at com.juyuansoft.shpms.dispatch.service.impl.CityWeatherForecastsServiceImpl$$EnhancerBySpringCGLIB$$2c0cf5c3.getCityWeatherForecastsList(<generated>) ~[classes!/:na] at com.juyuansoft.shpms.dispatch.job.CityWeatherForecastsJob.copyYesterdayShips(CityWeatherForecastsJob.java:38) ~[classes!/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111] at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.3.27.jar!/:5.3.27] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.27.jar!/:5.3.27] at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:95) [spring-context-5.3.27.jar!/:5.3.27] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_111] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_111] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_111] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_111] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] Caused by: org.apache.ibatis.executor.BatchExecutorException: com.juyuansoft.shpms.dispatch.mapper.CityWeatherForecastsMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: ORA-00933: SQL command not properly ended at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:148) ~[mybatis-3.5.0.jar!/:3.5.0] at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129) ~[mybatis-3.5.0.jar!/:3.5.0] at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122) ~[mybatis-3.5.0.jar!/:3.5.0] at org.apache.ibatis.executor.CachingExecutor.flushStatements(CachingExecutor.java:114) ~[mybatis-3.5.0.jar!/:3.5.0] at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:253) ~[mybatis-3.5.0.jar!/:3.5.0] ... 30 common frames omitted Caused by: java.sql.BatchUpdateException: ORA-00933: SQL command not properly ended at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:12296) ~[ojdbc7-12.1.0.2.0.jar!/:12.1.0.2.0] at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:246) ~[ojdbc7-12.1.0.2.0.jar!/:12.1.0.2.0] at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:3118) ~[druid-1.1.24.jar!/:1.1.24] at com.alibaba.druid.filter.FilterAdapter.statement_executeBatch(FilterAdapter.java:2507) ~[druid-1.1.24.jar!/:1.1.24] at com.alibaba.druid.filter.FilterEventAdapter.statement_executeBatch(FilterEventAdapter.java:279) ~[druid-1.1.24.jar!/:1.1.24] at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:3116) ~[druid-1.1.24.jar!/:1.1.24] at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeBatch(StatementProxyImpl.java:202) ~[druid-1.1.24.jar!/:1.1.24] at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeBatch(DruidPooledPreparedStatement.java:565) ~[druid-1.1.24.jar!/:1.1.24] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111] at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:78) ~[mybatis-3.5.0.jar!/:3.5.0] at com.sun.proxy.$Proxy858.executeBatch(Unknown Source) ~[na:na] at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:122) ~[mybatis-3.5.0.jar!/:3.5.0] ... 34 common frames omitted
最新发布
10-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值