J2EE
共 47 篇文章
spring cloud gateway 全局过滤器。
spring cloud gateway 网关yaml配置 。 server: port: 10010 spring: application: name: gateway cloud: gateway: discovery: locator: enabled: true #从注册中心寻找 routes: - id: hystrix_route uri: lb://web-service #web微服务 predicates: - Path=/api/web/** #访问微服务的路径 filters: - StripPrefix=2 #去除两个前缀目录 eureka: client: ser…
2019-03-17 23:11 · J2EE
netty简单的操作memcached
pom文件 <dependency> <groupId>io.netty</groupId> <artifactId>netty-example</artifactId> <version>4.1.8.Final</version> <exclusions> <exclusion> <artifactId>netty-tcnative</artifactId> <groupId>io.netty</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.netty</groupId> <artifa…
juc系列-Executor框架
转自 juc系列-Executor框架 什么是线程池 线程池: 管理 一组工作线程的资源池。 为什么使用线程池 1.避免反复创建回收线程,降低资源消耗。 2.提供线程的可管理性。 3.提高响应速度 如何创建线程池 ThreadPoolExecutor是jdk提供的线程池的服务类,基于ThreadPoolExecutor可以很容易将一个实现Runnable接口的任务放入线程池中执行,下面是ThreadPoolExecutor实现: //构造函数: public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keep…
2017-03-20 13:34 · J2EE
juc之CountDownLatch、CyclicBarrier和Semaphore例子
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; /** * * 保护一个重要(代码)部分防止一次超过 N 个线程进入。 在N 个线程之间发送信号。 * @author fansxnet * */ public class SemaphoreTest { public static void main(String[] args) { // 线程池 ExecutorService exec = Ex…
2017-03-19 17:23 · J2EE
netty客户端与服务端例子
package com.snailteam.netty; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocket…
freemaker集成spring
<bean id="freeMarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean"> <property name="templateLoaderPath" value="file:///data/tmpl/freemarker/" /> <property name="freemarkerSettings"> <props> <!-- 更新间隔 --> <prop key="template_update_delay">60</prop> <prop …
2017-02-26 19:00 · J2EE
spring集成Hessian插件配置改成自动注入。
原来的配置 <bean name="/UserService" class="org.springframework.remoting.caucho.HessianServiceExporter"> <property name="serviceInterface" value="com.snailteam.service.UserService"></property> <property name="service" ref="userServiceImp"></property> </bean> <bean class="org.springframework.remoting.cau…
2017-02-10 15:39 · J2EE
Java多线程
线程状态图 新建状态(New): 线程对象被创建后,就进入了新建状态。例如,Thread thread = new Thread()。 就绪状态(Runnable): 也被称为“可执行状态”。线程对象被创建后,其它线程调用了该对象的 start() 方法,从而来启动该线程。例如,thread.start()。运行中的线程调用 yield() 之后也会进入就绪状态。处于就绪状态的线程,随时可能被 CPU 调度执行。 运行状态(Running): 线程获取CPU权限进行执行。需要注意的是,线程只能从就绪状态进入到运行状态。 阻塞状态(Blocked): 阻塞状态是线程因为某种原因放弃 CPU 使…
2017-02-04 14:39 · J2EE
hash冲突解决
1、开放地址法有一个公式: m是hash表长度,di 是产生冲突的时候的增量序列 fi(key) = (f(key)+di) MOD m; 找到 fi(key) 位置空的放入此位置 ,当达到表尾m-1时,又从0开始探查. a.线性探测法 (di=0,1,2,3,......,m-1) b.二次探测法(线性补偿探测法) di=i^2,di=- (i^2); i=0,1,2,3,(m-1)/2 c.随机探测 di 是一组伪随机数列 使用一个确定性的算法计算出来的似乎是随机的数序,因此伪随机数实际上并不随机 比如电脑上的时间作为计算伪随机数的开始值。 2、再哈希法 当发生冲突时,使用第二个、第三个…
2017-01-23 18:30 · J2EE
Java并发任务处理例子
public void init() { super.init(); this.ioThreadPool = new ThreadPoolExecutor(50, 50, Long.MAX_VALUE, TimeUnit.SECONDS, new java.util.concurrent.LinkedTransferQueue<Runnable>(), new ThreadFactory() { AtomicLong id = new AtomicLong(); @Override public Thread newThread(final Runnable r) { Thread t = …
2014-02-12 16:06 · J2EE
JAVA动态代理模式
这是我要实现的效果 public static void main(String[] args) { UserDao proxy = (UserDao) BeanProxyFactory.getProxyObject(UserDaoImpl.class.getName()); proxy.save(new User());//我想实现保存的时候,自动调用一些动作 } 看代码 package org.dao; import org.pojo.User; public interface UserDao { public void save(User user); public void upd…
2012-10-03 01:01 · J2EE
paoding的分词使用
paoding下载 http://code.google.com/p/paoding/ paoding分词的默认配置 paoding-analysis-default.properties 配置全局的规则,{字典目录,切词规则} paoding分词的字典指定 paoding-dic-home.properties paoding自己的字典文件paoding/dic x-noise-*.dic是过滤字典,存放分词时过滤词和字;其他dic是定义一个完整的词。 paoding分词的切词策略 paoding-knives.properties paoding/dic/.compiled目录是生成二进…
solr3.5集成paoding和位置搜索及对solrj的使用。
http://xiaofancn.iteye.com/blog/1424252 http://wiki.apache.org/solr/Solrj http://hi.baidu.com/channing07/blog/item/cb840754a98fc7c9b645ae3e.html * https://github.com/dsmiley/SOLR-2155 关于位置的搜索的增强库 * http://wiki.apache.org/solr/SpatialSearch#SOLR-2155 为了让paoding适合高版本的solr3.5,我重新更换了一下paoding编译的部分jar包。…
日期处理DateUtils
import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; public class DateUtils { /** * 获取当前时间 * * @param date * @return */ public static Date getCurrentDate() { return new Date(System.currentTimeMillis()); } /** * 将时间置为…
2012-03-24 09:47 · J2EE
Cassandra的数据分布情况测试
1、规划种子节点ip和Token值的对应 4个种子节点ip 192.168.0.231 192.168.0.232 192.168.0.233 192.168.0.234 进入python,计算Token #192.168.0.231对应的Token为 >>> print 2 ** 127 / 4 * 1 42535295865117307932921825928971026432 #192.168.0.232对应的Token为 >>> print 2 ** 127 / 4 * 2 85070591730234615865843651857942052864 #192.168.0.233对应…
2012-03-16 15:09 · J2EE
使用hector操作Cassandra
http://rantav.github.com/hector/build/html/content/getting_started.html https://github.com/zznate/hector-examples.git private static final String DYN_KEYSPACE = "logdb"; private static final String DYN_CF = "user"; private static StringSerializer stringSerializer = StringSerializer.get(); private s…
2012-03-13 18:06 · J2EE
eclipse运行hadoop程序
参照hadoop-0.20.2/docs/quickstart.html 注:ssh-copy-id -i ~/.ssh/id_rsa.pub localhost,我的 用户名是fansxnet 配置我们的hadoop伪分布式,打开下面的页面,配置成功。 NameNode - http://localhost:50070/ JobTracker - http://localhost:50030/ mapreduce 9001 hdfs 9000 添加hadoop的eclipse的插件并重起eclipse。 hadoop-0.20.2/contrib/eclipse-plugin/hadoop…
2012-03-02 01:25 · J2EE
Tomcat solr 3.5.0 paoding集成
下载 solr3.5 tomcat paoding tomcat上添加solr应用 复制apache-solr-3.5.0\example\webapps\solr.war包到tomcat-7.0.21\webapps目录下。 复制apache-solr-3.5.0\example\solr文件夹到tomcat-7.0.21\webapps\solr文件夹下。 新建xml文件 tomcat-7.0.21\conf\Catalina\localhost\solr.xml <?xml version='1.0' encoding='utf-8'?> <Context docBase="${cat…
JPA+spring3+tile集成项目模板。
随着长时间的工作,框架都比较固定,稳定。没什么新鲜感了,故作一个小例子。以备以后用到。 Maven项目。
2012-01-13 21:43 · J2EE
infinispan5的MapReduce使用
参考 https://docs.jboss.org/author/display/ISPN/Infinispan+Distributed+Execution+Framework#InfinispanDistributedExecutionFramework-MapReducemodel 首先下载我们的infinispan5的运行环境 https://github.com/infinispan/infinispan-quickstart.git 中org.infinispan.quickstart.clusteredcache.distribution.NodeClient类为 package…
2011-11-18 18:06 · J2EE