Spring线程池服务

线程池对于执行同步和异步过程非常重要。 本文介绍如何使用Spring开发和监视线程池服务。 创建线程池已通过两种替代方法进行了说明。

二手技术

JDK 1.6.0_21
Spring3.0.5
Maven的3.0.2

步骤1:建立已完成的专案

创建一个Maven项目,如下所示。 (可以使用Maven或IDE插件来创建它)。

步骤2:图书馆

Spring依赖项已添加到Maven的pom.xml中。

<!-- Spring 3 dependencies -->
<dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version>
</dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version>
</dependency>

为了创建runnable-jar,可以使用以下插件。

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>1.3.1</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><transformers><transformerimplementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"><mainClass>com.otv.exe.Application</mainClass></transformer><transformerimplementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"><resource>META-INF/spring.handlers</resource></transformer><transformerimplementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"><resource>META-INF/spring.schemas</resource></transformer></transformers></configuration></execution></executions>
</plugin>

第3步:创建任务班

通过实现Runnable接口可以创建一个新的TestTask类。 此类显示要执行的任务。

package com.otv.task;import org.apache.log4j.Logger;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public class TestTask implements Runnable {private static Logger log = Logger.getLogger(TestTask.class);String taskName;public TestTask() {}public TestTask(String taskName) {this.taskName = taskName;}public void run() {try {log.debug(this.taskName + " : is started.");Thread.sleep(10000);log.debug(this.taskName + " : is completed.");} catch (InterruptedException e) {log.error(this.taskName + " : is not completed!");e.printStackTrace();}}@Overridepublic String toString() {return (getTaskName());}public String getTaskName() {return taskName;}public void setTaskName(String taskName) {this.taskName = taskName;}
}

步骤4:建立TestRejectedExecutionHandler类别

通过实现RejectedExecutionHandler接口来创建TestRejectedExecutionHandler类。 如果没有空闲线程并且队列溢出,任务将被拒绝。 此类处理被拒绝的任务。

package com.otv.handler;import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;import org.apache.log4j.Logger;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public class TestRejectedExecutionHandler implements RejectedExecutionHandler {private static Logger log = Logger.getLogger(TestRejectedExecutionHandler.class);public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {log.debug(runnable.toString() + " : has been rejected");}
}

步骤5:建立ITestThreadPoolExecutorService接口

ITestThreadPoolExecutorService接口已创建。

package com.otv.srv;import java.util.concurrent.ThreadPoolExecutor;import com.otv.handler.TestRejectedExecutionHandler;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public interface ITestThreadPoolExecutorService {public ThreadPoolExecutor createNewThreadPool();public int getCorePoolSize();public void setCorePoolSize(int corePoolSize);public int getMaxPoolSize();public void setMaxPoolSize(int maximumPoolSize);public long getKeepAliveTime();public void setKeepAliveTime(long keepAliveTime);public int getQueueCapacity();public void setQueueCapacity(int queueCapacity);public TestRejectedExecutionHandler getTestRejectedExecutionHandler();public void setTestRejectedExecutionHandler(TestRejectedExecutionHandler testRejectedExecutionHandler);}

步骤6:建立TestThreadPoolExecutorService类别

通过实现ITestThreadPoolExecutorService接口来创建TestThreadPoolExecutorService类。 此类创建一个新的线程池。

package com.otv.srv;import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;import com.otv.handler.TestRejectedExecutionHandler;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public class TestThreadPoolExecutorService implements ITestThreadPoolExecutorService {private int  corePoolSize;private int  maxPoolSize;private long keepAliveTime;private int  queueCapacity;TestRejectedExecutionHandler testRejectedExecutionHandler;public ThreadPoolExecutor createNewThreadPool() {ThreadPoolExecutor executor = new ThreadPoolExecutor(getCorePoolSize(),getMaxPoolSize(),getKeepAliveTime(),TimeUnit.SECONDS,new ArrayBlockingQueue(getQueueCapacity()),getTestRejectedExecutionHandler());return executor;}public int getCorePoolSize() {return corePoolSize;}public void setCorePoolSize(int corePoolSize) {this.corePoolSize = corePoolSize;}public int getMaxPoolSize() {return maxPoolSize;}public void setMaxPoolSize(int maxPoolSize) {this.maxPoolSize = maxPoolSize;}public long getKeepAliveTime() {return keepAliveTime;}public void setKeepAliveTime(long keepAliveTime) {this.keepAliveTime = keepAliveTime;}public int getQueueCapacity() {return queueCapacity;}public void setQueueCapacity(int queueCapacity) {this.queueCapacity = queueCapacity;}public TestRejectedExecutionHandler getTestRejectedExecutionHandler() {return testRejectedExecutionHandler;}public void setTestRejectedExecutionHandler(TestRejectedExecutionHandler testRejectedExecutionHandler) {this.testRejectedExecutionHandler = testRejectedExecutionHandler;}
}

步骤7:创建IThreadPoolMonitorService接口

IThreadPoolMonitorService接口已创建。

package com.otv.monitor.srv;import java.util.concurrent.ThreadPoolExecutor;public interface IThreadPoolMonitorService extends Runnable {public void monitorThreadPool();public ThreadPoolExecutor getExecutor();public void setExecutor(ThreadPoolExecutor executor);}

步骤8:创建ThreadPoolMonitorService类

ThreadPoolMonitorService类是通过实现IThreadPoolMonitorService接口创建的。 此类监视创建的线程池。

package com.otv.monitor.srv;import java.util.concurrent.ThreadPoolExecutor;
import org.apache.log4j.Logger;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public class ThreadPoolMonitorService implements IThreadPoolMonitorService {private static Logger log = Logger.getLogger(ThreadPoolMonitorService.class);ThreadPoolExecutor executor;private long monitoringPeriod; public void run() {try {while (true){monitorThreadPool();Thread.sleep(monitoringPeriod*1000);}} catch (Exception e) {log.error(e.getMessage());}}public void monitorThreadPool() {StringBuffer strBuff = new StringBuffer();strBuff.append("CurrentPoolSize : ").append(executor.getPoolSize());strBuff.append(" - CorePoolSize : ").append(executor.getCorePoolSize());strBuff.append(" - MaximumPoolSize : ").append(executor.getMaximumPoolSize());strBuff.append(" - ActiveTaskCount : ").append(executor.getActiveCount());strBuff.append(" - CompletedTaskCount : ").append(executor.getCompletedTaskCount());strBuff.append(" - TotalTaskCount : ").append(executor.getTaskCount());strBuff.append(" - isTerminated : ").append(executor.isTerminated());log.debug(strBuff.toString());}public ThreadPoolExecutor getExecutor() {return executor;}public void setExecutor(ThreadPoolExecutor executor) {this.executor = executor;}   public long getMonitoringPeriod() {return monitoringPeriod;}public void setMonitoringPeriod(long monitoringPeriod) {this.monitoringPeriod = monitoringPeriod;}
}

第9步:创建入门类

启动器类已创建。

package com.otv.start;import java.util.concurrent.ThreadPoolExecutor;import org.apache.log4j.Logger;import com.otv.handler.TestRejectedExecutionHandler;
import com.otv.monitor.srv.IThreadPoolMonitorService;
import com.otv.monitor.srv.ThreadPoolMonitorService;
import com.otv.srv.ITestThreadPoolExecutorService;
import com.otv.srv.TestThreadPoolExecutorService;
import com.otv.task.TestTask;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public class Starter {private static Logger log = Logger.getLogger(TestRejectedExecutionHandler.class);IThreadPoolMonitorService threadPoolMonitorService;ITestThreadPoolExecutorService testThreadPoolExecutorService;public void start() {// A new thread pool is created...ThreadPoolExecutor executor = testThreadPoolExecutorService.createNewThreadPool();executor.allowCoreThreadTimeOut(true);// Created executor is set to ThreadPoolMonitorService...threadPoolMonitorService.setExecutor(executor);// ThreadPoolMonitorService is started...Thread monitor = new Thread(threadPoolMonitorService);monitor.start();// New tasks are executed...for(int i=1;i<10;i++) {executor.execute(new TestTask("Task"+i));}try {Thread.sleep(40000);} catch (Exception e)   {log.error(e.getMessage());}for(int i=10;i<19;i++) {executor.execute(new TestTask("Task"+i));}// executor is shutdown...executor.shutdown();}   public IThreadPoolMonitorService getThreadPoolMonitorService() {return threadPoolMonitorService;}public void setThreadPoolMonitorService(IThreadPoolMonitorService threadPoolMonitorService) {this.threadPoolMonitorService = threadPoolMonitorService;}public ITestThreadPoolExecutorService getTestThreadPoolExecutorService() {return testThreadPoolExecutorService;}public void setTestThreadPoolExecutorService(ITestThreadPoolExecutorService testThreadPoolExecutorService) {this.testThreadPoolExecutorService = testThreadPoolExecutorService;}
}

步骤10:创建应用程序类

应用程序类已创建。 此类运行应用程序。

package com.otv.start;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @author onlinetechvision.com* @since 17 Oct 2011* @version 1.0.0**/
public class Application {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");Starter starter = (Starter) context.getBean("Starter");starter.start();}}

步骤11:创建applicationContext.xml

applicationContext.xml已创建。

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- Beans Declaration --><bean id="TestTask" class="com.otv.task.TestTask"></bean><bean id="ThreadPoolMonitorService" class="com.otv.monitor.srv.ThreadPoolMonitorService"><property name="monitoringPeriod"  value="5" /></bean><bean id="TestRejectedExecutionHandler" class="com.otv.handler.TestRejectedExecutionHandler"></bean><bean id="TestThreadPoolExecutorService" class="com.otv.srv.TestThreadPoolExecutorService"><property name="corePoolSize"  value="1" /><property name="maxPoolSize"   value="3" /><property name="keepAliveTime" value="10" /><property name="queueCapacity" value="3" /><property name="testRejectedExecutionHandler" ref="TestRejectedExecutionHandler" /></bean><bean id="Starter" class="com.otv.start.Starter"><property name="threadPoolMonitorService" ref="ThreadPoolMonitorService" /><property name="testThreadPoolExecutorService" ref="TestThreadPoolExecutorService" /></bean>
</beans>

步骤12:创建线程池的替代方法

Spring提供的ThreadPoolTask​​Executor类也可以用于创建线程池。

<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"><property name="corePoolSize"  value="1" /><property name="maxPoolSize"   value="3" /><property name="queueCapacity" value="3" />
</bean><bean id="testTaskExecutor" class="TestTaskExecutor"><constructor-arg ref="threadPoolTaskExecutor" />
</bean>

步骤13:建立专案

生成OTV_Spring_ThreadPool项目后,将创建OTV_Spring_ThreadPool-0.0.1-SNAPSHOT.jar

步骤14:运行项目

运行创建的OTV_Spring_ThreadPool-0.0.1-SNAPSHOT.jar文件后,将在下面显示输出日志:

18.10.2011 20:08:48 DEBUG (TestRejectedExecutionHandler.java:19) - Task7 : has been rejected
18.10.2011 20:08:48 DEBUG (TestRejectedExecutionHandler.java:19) - Task8 : has been rejected
18.10.2011 20:08:48 DEBUG (TestRejectedExecutionHandler.java:19) - Task9 : has been rejected
18.10.2011 20:08:48 DEBUG (TestTask.java:25) - Task1 : is started.
18.10.2011 20:08:48 DEBUG (TestTask.java:25) - Task6 : is started.
18.10.2011 20:08:48 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 2 - CompletedTaskCount : 0 - TotalTaskCount : 5 - isTerminated : false
18.10.2011 20:08:48 DEBUG (TestTask.java:25) - Task5 : is started.
18.10.2011 20:08:53 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 0 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:08:58 DEBUG (TestTask.java:27) - Task6 : is completed.
18.10.2011 20:08:58 DEBUG (TestTask.java:27) - Task1 : is completed.
18.10.2011 20:08:58 DEBUG (TestTask.java:25) - Task3 : is started.
18.10.2011 20:08:58 DEBUG (TestTask.java:25) - Task2 : is started.
18.10.2011 20:08:58 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 2 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:08:58 DEBUG (TestTask.java:27) - Task5 : is completed.
18.10.2011 20:08:58 DEBUG (TestTask.java:25) - Task4 : is started.
18.10.2011 20:09:03 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 3 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:09:08 DEBUG (TestTask.java:27) - Task2 : is completed.
18.10.2011 20:09:08 DEBUG (TestTask.java:27) - Task3 : is completed.
18.10.2011 20:09:08 DEBUG (TestTask.java:27) - Task4 : is completed.
18.10.2011 20:09:08 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 0 - CompletedTaskCount : 6 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:09:13 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 0 - CompletedTaskCount : 6 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:09:18 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 0 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 0 - CompletedTaskCount : 6 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:09:23 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 0 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 0 - CompletedTaskCount : 6 - TotalTaskCount : 6 - isTerminated : false
18.10.2011 20:09:28 DEBUG (TestTask.java:25) - Task10 : is started.
18.10.2011 20:09:28 DEBUG (TestRejectedExecutionHandler.java:19) - Task16 : has been rejected
18.10.2011 20:09:28 DEBUG (TestRejectedExecutionHandler.java:19) - Task17 : has been rejected
18.10.2011 20:09:28 DEBUG (TestRejectedExecutionHandler.java:19) - Task18 : has been rejected
18.10.2011 20:09:28 DEBUG (TestTask.java:25) - Task14 : is started.
18.10.2011 20:09:28 DEBUG (TestTask.java:25) - Task15 : is started.
18.10.2011 20:09:28 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 6 - TotalTaskCount : 12 - isTerminated : false
18.10.2011 20:09:33 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 6 - TotalTaskCount : 12 - isTerminated : false
18.10.2011 20:09:38 DEBUG (TestTask.java:27) - Task10 : is completed.
18.10.2011 20:09:38 DEBUG (TestTask.java:25) - Task11 : is started.
18.10.2011 20:09:38 DEBUG (TestTask.java:27) - Task14 : is completed.
18.10.2011 20:09:38 DEBUG (TestTask.java:27) - Task15 : is completed.
18.10.2011 20:09:38 DEBUG (TestTask.java:25) - Task12 : is started.
18.10.2011 20:09:38 DEBUG (TestTask.java:25) - Task13 : is started.
18.10.2011 20:09:38 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 9 - TotalTaskCount : 12 - isTerminated : false
18.10.2011 20:09:43 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 3 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 3 - CompletedTaskCount : 9 - TotalTaskCount : 12 - isTerminated : false
18.10.2011 20:09:48 DEBUG (TestTask.java:27) - Task11 : is completed.
18.10.2011 20:09:48 DEBUG (TestTask.java:27) - Task13 : is completed.
18.10.2011 20:09:48 DEBUG (TestTask.java:27) - Task12 : is completed.
18.10.2011 20:09:48 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 0 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 0 - CompletedTaskCount : 12 - TotalTaskCount : 12 - isTerminated : true
18.10.2011 20:09:53 DEBUG (ThreadPoolMonitorService.java:39) - CurrentPoolSize : 0 - CorePoolSize : 1 - MaximumPoolSize : 3 - ActiveTaskCount : 0 - CompletedTaskCount : 12 - TotalTaskCount : 12 - isTerminated : true

步骤15:下载

OTV_Spring_ThreadPool

参考: 如何使用我们JCG合作伙伴提供的 Spring开发和监视线程池服务   在线技术愿景博客上的Eren Avsarogullari。


翻译自: https://www.javacodegeeks.com/2012/02/spring-thread-pool-services.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/373303.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

我的世界java村民繁殖_我的世界:Java19w08a更新,村民加强守卫,小狐狸背叛

虽然这句话很绕口&#xff0c;其实意思很简单&#xff0c;那就是之前的隐身药水没有什么用&#xff0c;该被打还是被打。因为这个可是害惨了流浪商人&#xff0c;不过这次好了&#xff0c;流浪商人在喝了隐身药水之后就能安全度过晚上了。NO.3 皮革马铠马铠是属于马的盔甲&…

欧莱雅眉笔banner个人设计

眉笔名称&#xff1a;眉笔大师三头塑形眉笔 &#xff0c;之所以没用吧这个商品名称放大&#xff0c;是我觉得它是一个名称&#xff0c;而我把自己想的广告词“出彩只需一笔” 放大不仅能凸显出这只笔的强大&#xff0c;还表示了一种有了我这支眉笔你会更出彩更漂亮&#xff0c…

使用带有注释和JQuery的Spring MVC 3的Ajax

与Ajax一起工作对我来说一直很有趣&#xff01; 是不是 &#xff1f; 我将使您轻松将Ajax与Spring MVC 3和JQuery结合使用。 这篇文章将向您说明如何在工业编码的现实生活中使用Ajax。 和往常一样&#xff0c;我们将在Spring MVC 3框架中以Ajax的实际示例为例&#xff0c;并将其…

java百度云文件上传_关于如何在自己项目集成百度云BCE文件上传STS方案

1、 项目背景由于本人项目需要&#xff0c;需要在视频点播服务之中需要加载字幕文件(通用格式srt)&#xff0c;经过比较好几家的公有云服务&#xff0c;最后选择只有百度云提供字幕服务。字幕&#xff1a;我们通常在观看外语电影的是&#xff0c;没有国语版时候只能通过下载字幕…

hdu 3507 Print Article(斜率优化DP)

题目链接&#xff1a;hdu 3507 Print Article 题意&#xff1a; 每个字有一个值&#xff0c;现在让你分成k段打印&#xff0c;每段打印需要消耗的值用那个公式计算&#xff0c;现在让你求最小值 题解&#xff1a; 设dp[i]表示前i个字符需要消耗的最小值&#xff0c;那么有dp[i]…

第三章 consul服务注册与服务查询

1、定义一个服务 https://www.consul.io/docs/agent/services.html 该方法是服务注册中提供服务的最常用的方法。 关于服务的定义&#xff1a;服务的属性我们会在后边每出现一个总结一个&#xff0c;最后再做总结。 2、服务注册 2.1、创建服务文件所存放的文件夹 说明&#xff…

coreos 安装mysql_CoreOS 在 PC 上快速安装方法指南

意义能够以最快的速度安装部署Linux操作系统。安装快速简单&#xff0c;几乎不花时间就可以开始运行Docker。运行速度非常快。使用内存硬盘。我的情况win8 笔记本偶尔玩游戏&#xff0c;但是装Linux双系统可能需要我一天的时间来完成。我的所有业务都只需要在Docker中跑就可以了…

Session 的配置和特性

session的配置 对于session的配置是php.ini中配置 session数据都是保存在文本文件中 设置session文件的保存位置 说明&#xff1a; 默认是保存在windows/temp目录 设置session保存作为客户端标识的数据使用cookie 设置session保存客户端标识的数据&#xff0c;只使用cookie 说明…

OAuth与Spring Security

摘自Wikipedia&#xff1a; OAuth &#xff08; 开放式身份验证 &#xff09;是一种开放式身份验证标准。 它允许用户与其他站点共享存储在一个站点上的私有资源&#xff08;例如照片&#xff0c;视频&#xff0c;联系人列表&#xff09;&#xff0c;而不必发出其凭据&#xff…

UIViewController生命周期

UIViewController生命周期 UIViewController生命周期 posted on 2016-04-07 20:15 相而勿绝 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/fmdxiangdui/p/5365249.html

众筹源码 php,助创cms众筹源码系统v1.0

什么是助创cms众筹系统?使用“预约团购”的众筹方式给自己的创意争取大家的关注和支持&#xff0c;是近年来非常火热的一种融资模式&#xff0c;助创cms众筹系统可以10分钟帮你打造一个和京东众筹一样的平台&#xff0c;包含产品众筹和公益众筹两个部分&#xff0c;可以直接拿…

69 个经典 Spring 面试题和答案

Spring 概述 什么是spring?Spring 是个java企业级应用的开源开发框架。Spring主要用来开发Java应用&#xff0c;但是有些扩展是针对构建J2EE平台的web应用。Spring 框架目标是简化Java企业级应用开发&#xff0c;并通过POJO为基础的编程模型促进良好的编程习惯。使用Spring框架…

高性能MySql

1、索引是对DB优化最有效的方式 varchar(10)定义的是字符的个数&#xff0c;如果是utf-8的话&#xff0c;最大是3X10个字节 二、索引类型 1、MySql的索引是在存储引擎层实现的&#xff0c;各个存储引擎的的索引方式也是不同的 2、B-Tree索引 MyISAM索引通过数据的物理位置引用被…

Java Swing井字游戏

大家好&#xff01; 哇&#xff0c;自从我在这里发布了东西以来已经有一段时间了&#xff01; 我必须说我真的很想写东西&#xff0c;而且我保证我不会再陷入“作家的障碍”。 希望 ..最近两个月发生了很多事情&#xff0c;我有很多话要说。 但是在这篇文章中&#xff0c;我只是…

event php,PHP event 事件机制

/** PHP 事件机制*/class baseClass{private $_e;public function __set($name,$value){if( strncasecmp($name,"on",2) 0 ){if(!isset($this->_e[$name]))$this->_e[$name] array();return array_push($this->_e[$name] , $value);}}public function __g…

Android JNI编程(五)——C语言的静态内存分配、动态内存分配、动态创建数组...

版权声明&#xff1a;本文出自阿钟的博客&#xff0c;转载请注明出处:http://blog.csdn.net/a_zhon/。 目录(?)[] 一&#xff1a;什么是静态内存什么又是动态内存呢&#xff1f; 静态内存&#xff1a;是指在程序开始运行时由编译器分配的内存&#xff0c;它的分配是在程序开始…

配置MyBatis 3

MyBatis是一个非常流行且也是最有效的SQL映射框架。 MyBatis可用于Java和.net语言。 MyBatis并不是Hibernate的真正替代品&#xff0c;但是我们可以使用该框架来减少MyBatis提供的高效和高性能的数据库相关代码。 本教程将向您展示使用数据库配置MyBatis 3的步骤。 MyBatis 3支…

java中datetime类型转换,Java中日期格式和其他类型转换详解

涉及的核心类&#xff1a;Date类、SimpleDateFormat类、Calendar类一、Date型与long型Date型转换为long型Date date new Date();//取得当前时间Date类型long date2long date.getTime();//Date转longlong型转换为Date型long cur System.currentTimeMills();//取得当前时间lon…

GWT MVP变得简单

GWT Model-View-Presenter是用于大规模应用程序开发的设计模式。 它源于MVC&#xff0c;它在视图和逻辑之间进行划分&#xff0c;并有助于创建结构良好&#xff0c;易于测试的代码。 为了帮助像我这样的懒惰开发人员&#xff0c;我研究了如何减少使用声明式UI时要编写的类和接口…

今年计划要看的书全部备齐

上个月购买的书《今年计划看的书其中几本》 http://www.cnblogs.com/insus/p/5325513.html 昨天购买的书回来了&#xff0c;今年计划要看的书全部备齐。《MongoDB》&#xff0c;《深入理解Bootstarp》和《ASP.NETSignalR编程实践》…… 转载于:https://www.cnblogs.com/in…