??xml version="1.0" encoding="utf-8" standalone="yes"?>久久青青草原亚洲AV无码麻豆
,亚洲一区二区精品视频,亚洲国产婷婷香蕉久久久久久 http://www.tkk7.com/miaoyachun/category/50699.htmlzh-cn Fri, 08 Dec 2017 06:50:38 GMT Fri, 08 Dec 2017 06:50:38 GMT 60 Spring boot外部配置-配置中心?/title> http://www.tkk7.com/miaoyachun/archive/2017/12/08/432940.htmlMilo的v?/dc:creator>Milo的v?/author>Fri, 08 Dec 2017 06:13:00 GMT http://www.tkk7.com/miaoyachun/archive/2017/12/08/432940.html http://www.tkk7.com/miaoyachun/comments/432940.html http://www.tkk7.com/miaoyachun/archive/2017/12/08/432940.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/432940.html http://www.tkk7.com/miaoyachun/services/trackbacks/432940.html /** * 重蝲合ƈ属性实?br /> * 先加载file propertiesQ?然后q入ZK配置中心d的properties * * @return 合ƈ后的属性集?br /> * @throws IOException 异常 */ @Override protected Properties mergeProperties () throws IOException { Properties result = new Properties(); // 加蝲父类的配|?br /> Properties mergeProperties = super .mergeProperties(); result.putAll(mergeProperties); // 加蝲从zk中读取到的配|?br /> Map<String, String> configs = loadZkConfigs(); result.putAll(configs); return result; } q个实现在spring目里用hq是挺顺手的, 但是q期部分spring-boot目里发现这Uplaceholder的实现跟spring boot的@ConfigurationProperties(prefix = "xxx") 不能很好的配合工? 也就是属性没有被resolve处理, 用@Value的方式确可以d, 但是@Value配置h如果属性多的话q是挺繁琐的, q是們用@ConfigurationProperties的prefix, 于是看了下spring boot的文发?code>PropertySource order:
* Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active). * @TestPropertySource annotations on your tests. * @SpringBootTest#properties annotation attribute on your tests. * Command line arguments. * Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property) * ServletConfig init parameters. * ServletContext init parameters. * JNDI attributes from java:comp/env. * Java System properties (System.getProperties()). * OS environment variables. * A RandomValuePropertySource that only has properties in random.*. * Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants) * Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants) * Application properties outside of your packaged jar (application.properties and YAML variants). * Application properties packaged inside your jar (application.properties and YAML variants). * @PropertySource annotations on your @Configuration classes. * Default properties (specified using SpringApplication.setDefaultProperties).
不难发现其会查Java system propeties里的属? 也就是说, 只要把mergerPropertiesd的属性写入Java system props里即? 看了下源? 扑ֈ个切入点/** * 重蝲处理属性实?br /> * Ҏ选项, 军_是否合q后的props写入pȝ属? Spring boot需?br /> * * @param beanFactoryToProcess * @param props 合ƈ后的属?br /> * @throws BeansException */ @Override protected void processProperties (ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException { // 原有逻辑 super .processProperties(beanFactoryToProcess, props); // 写入到系l属?br /> if (writePropsToSystem ) { // write all properties to system for spring boot Enumeration<?> propertyNames = props.propertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); String propertyValue = props.getProperty(propertyName); System.setProperty (propertyName, propertyValue); } } } 为避免媄响过? 讄了个开? 是否写入pȝ属? 如果是spring boot的项? 开? q样对线上非spring boot目做到影响最? 然后spring boot的@ConfigurationProperties完美d属? 具体代码? org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor@Override public Object postProcessBeforeInitialization (Object bean, String beanName) throws BeansException { ConfigurationProperties annotation = AnnotationUtils .findAnnotation (bean.getClass(), ConfigurationProperties .class ); if (annotation != null ) { postProcessBeforeInitialization(bean, beanName, annotation); } annotation = this .beans .findFactoryAnnotation(beanName, ConfigurationProperties .class ); if (annotation != null ) { postProcessBeforeInitialization(bean, beanName, annotation); } return bean; } ]]> Junit @AfterClass讉K注入对象的方?/title> http://www.tkk7.com/miaoyachun/archive/2017/04/15/432461.htmlMilo的v?/dc:creator>Milo的v?/author>Sat, 15 Apr 2017 02:32:00 GMT http://www.tkk7.com/miaoyachun/archive/2017/04/15/432461.html http://www.tkk7.com/miaoyachun/comments/432461.html http://www.tkk7.com/miaoyachun/archive/2017/04/15/432461.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/432461.html http://www.tkk7.com/miaoyachun/services/trackbacks/432461.html S pring默认不允许对cȝ变量, 也就是静态变量进行注入操? 但是在某些场景比如单元测试的@AfterClass要访问注入对? 而Junit的这个方法必L静态的, 也就产生了悖?解决思\有两?
思\1: 惛_法对静态变量注? 也就是绕qSpring只能q行非静态变量才能注入依赖的壁垒
思\2: 惛_法@AfterClass攚wؓ非静?/span>
实现Junit RunListener, 覆盖testRunFinishedҎ, q里d现类似@AfterClass的功? q个Ҏ是非静态的
不要用Junit, 改用TestNG, TestNG里的AfterClass是非静态的
用Spring的TestExecutionListeners, 实现个Listener, 里面也有个类似非静态的AfterClass的实? 覆盖实现p
思\2的几个方法都可以实现, 但是单元试Runner需要用
而且改用TestNG工程大, 只能攑ּ掉这个思\
l箋走思\1, 只能ȝqSpring的依赖注入的static壁垒? 具体代码如下:
@Autowired
private Destination dfsOperationQueue ;
private static Destination dfsOperationQueueStatic ; // static version
@Autowired
private MessageQueueAPI messageQueueAPI ;
private static MessageQueueAPI messageQueueAPIStatic ; // static version
@PostConstruct
public void init () {
dfsOperationQueueStatic = this . dfsOperationQueue ;
messageQueueAPIStatic = this . messageQueueAPI ;
}
@AfterClass
public static void afterClass () {
MessageVO messageVO = messageQueueAPIStatic . removeDestination ( dfsOperationQueueStatic );
System . out . println ( messageVO );
}
其实是用了@PostConstruct 来个h换柱而已, 多声明个静态成员指向非静态对? 两者其实是一个对?/span>
]]> 通过rest api理activemq http://www.tkk7.com/miaoyachun/archive/2016/10/22/431914.htmlMilo的v?/dc:creator>Milo的v?/author>Sat, 22 Oct 2016 09:31:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/10/22/431914.html http://www.tkk7.com/miaoyachun/comments/431914.html http://www.tkk7.com/miaoyachun/archive/2016/10/22/431914.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/431914.html http://www.tkk7.com/miaoyachun/services/trackbacks/431914.html 知道activemq现在已经支持了rest api, 但是官方对这部分的介l一W带q?(http://activemq.apache.org/rest.html),
通过google居然也没搜到一些有用的, 比如像删除一个destination, 都是问的?然后没下? 于是׃一些心思研I了一?
首先通过rest api获取当前版本所有已支持的协?/p>
http://172.30.43.206:8161/api/jolokia/list
然后Ҏjson输出关于removeTopic, removeQueue的mbean实现通过rest api删除destination的方? 注意到用GETh而不是POST,不然会报?(官网的例子里用的wgetl的灉|, 开始用了POST老报?
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.DefaultHttpClient; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import javax.jms.Destination; import javax.jms.JMSException; import java.util.Arrays; public class MessageQueueAdmin { private static final RestTemplate restTemplate = getRestTemplate( " admin " , " admin " ); private static String brokerHost = " 172.30.43.206 " ; private static String adminConsolePort = " 8161 " ; private static String protocol = " http " ; public static void removeDestination(Destination destination) throws JMSException { String destName, destType; if (destination instanceof ActiveMQQueue) { destName = ((ActiveMQQueue) destination).getQueueName(); destType = " Queue " ; } else { destName = ((ActiveMQTopic) destination).getTopicName(); destType = " Topic " ; } // build urls String url = String.format( " %s://%s:%s/api/jolokia/exec/org.apache.activemq: " + " brokerName=localhost,type=Broker/remove%s/%s " , protocol, brokerHost, adminConsolePort, destType, destName); System.out.println(url); // do operation HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity < String > entity = new HttpEntity < String > ( " parameters " , headers); ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, entity, String. class ); System.out.println(response.getBody()); } public static void main(String[] args) throws JMSException { ActiveMQTopic topic = new ActiveMQTopic( " test-activemq-topic " ); removeDestination(topic); } private static RestTemplate getRestTemplate(String user, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); httpClient.setCredentialsProvider(credentialsProvider); ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient); return new RestTemplate(rf); } }
其他的请?应该都是cMjolokia的exec get request的格?
https://jolokia.org/reference/html/protocol.html#exec
<base url>/exec/<mbean name>/<operation name>/<arg1>/<arg2>/ . ]]>JmsTemplate CLIENT_ACKNOWLEDGE 模式下receive消息的问?/title> http://www.tkk7.com/miaoyachun/archive/2016/10/12/431885.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 12 Oct 2016 08:32:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/10/12/431885.html http://www.tkk7.com/miaoyachun/comments/431885.html http://www.tkk7.com/miaoyachun/archive/2016/10/12/431885.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/431885.html http://www.tkk7.com/miaoyachun/services/trackbacks/431885.html protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException { try { // Use transaction timeout (if available). long timeout = getReceiveTimeout(); JmsResourceHolder resourceHolder = (JmsResourceHolder) TransactionSynchronizationManager.getResource(getConnectionFactory()); if (resourceHolder != null && resourceHolder.hasTimeout()) { timeout = Math.min(timeout, resourceHolder.getTimeToLiveInMillis()); } Message message = doReceive(consumer, timeout); if (session.getTransacted()) { // Commit necessary - but avoid commit call within a JTA transaction. if (isSessionLocallyTransacted(session)) { // Transacted session created by this template -> commit. JmsUtils.commitIfNecessary(session); } } else if (isClientAcknowledge(session)) { // Manually acknowledge message, if any. if (message != null ) { message.acknowledge(); } } return message; } finally { JmsUtils.closeMessageConsumer(consumer); } }
但是使用异步listener ׃会出现这个情况,搜了下googleQ发现果然存在这个问?br /> https://jira.spring.io/browse/SPR-12995 https://jira.spring.io/browse/SPR-13255 http://louisling.iteye.com/blog/241073
同步方式拉取消息Q暂时没扑ֈ好的装Q只能暂时用q。或者尽量用listener, q个问题暂时标记下,或者谁有更好的解决Ҏ可以comment?img src ="http://www.tkk7.com/miaoyachun/aggbug/431885.html" width = "1" height = "1" /> ]]> Spring中classpath与classpath*的区?/title> http://www.tkk7.com/miaoyachun/archive/2016/05/26/430666.htmlMilo的v?/dc:creator>Milo的v?/author>Thu, 26 May 2016 06:14:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/05/26/430666.html http://www.tkk7.com/miaoyachun/comments/430666.html http://www.tkk7.com/miaoyachun/archive/2016/05/26/430666.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/430666.html http://www.tkk7.com/miaoyachun/services/trackbacks/430666.html http://stackoverflow.com/questions/3294423/spring-classpath-prefix-difference
SIMPLE DEFINITION The classpath*:conf/appContext.xml simply means that all appContext.xml files under conf folders in all your jars on the classpath will be picked up and joined into one big application context. In contrast, classpath:conf/appContext.xml will load only one such file the first one found on your classpath. < bean id ="propertyConfigurer" class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > < property name ="locations" > < list > < value > classpath:*.properties</ value > < value > classpath*:*.properties</ value > </ list > </ property > </ bean > ]]> When launched from .exe IDEA looks for Java in a following order http://www.tkk7.com/miaoyachun/archive/2016/05/16/430516.htmlMilo的v?/dc:creator>Milo的v?/author>Mon, 16 May 2016 00:49:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/05/16/430516.html http://www.tkk7.com/miaoyachun/comments/430516.html http://www.tkk7.com/miaoyachun/archive/2016/05/16/430516.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/430516.html http://www.tkk7.com/miaoyachun/services/trackbacks/430516.html IDEA_JDK (or IDEA_JDK_64) environment variable jre/ (or jre64/) directory in IDEA home registry JDK_HOME environment variable JAVA_HOME environment variable ]]> java修改stdout的历史输?/title> http://www.tkk7.com/miaoyachun/archive/2016/04/21/430179.htmlMilo的v?/dc:creator>Milo的v?/author>Thu, 21 Apr 2016 09:06:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/04/21/430179.html http://www.tkk7.com/miaoyachun/comments/430179.html http://www.tkk7.com/miaoyachun/archive/2016/04/21/430179.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/430179.html http://www.tkk7.com/miaoyachun/services/trackbacks/430179.html ANSI code 用java写了个简单的例子Q例子就是把曄的output修改为其他字W串q恢复之后的打印Q代码里加了sleepQ主要方便理解各U控制序列的含义 // print some test messages System.out.println( " 1 " ); Thread.sleep( 1000 ); System.out.println( " 22 " ); Thread.sleep( 1000 ); System.out.println( " 333 " ); Thread.sleep( 1000 ); System.out.println( " 4444 " ); Thread.sleep( 1000 ); /** * modify "333" to "-" */ // Move up two lines int count = 2 ; System.out.print(String.format( " \033[%dA " , count)); Thread.sleep( 1000 ); // Erase current line content System.out.print( " \033[2K " ); Thread.sleep( 1000 ); // update with new content System.out.print( " - " ); Thread.sleep( 1000 ); // Move down two lines System.out.print(String.format( " \033[%dB " , count)); Thread.sleep( 1000 ); // Move cursor to left beginning System.out.print(String.format( " \033[D " , count)); // continue print others Thread.sleep( 1000 ); System.out.println( " 55555 " ); Thread.sleep( 1000 );
]]> zookeeper学习 http://www.tkk7.com/miaoyachun/archive/2016/03/31/429913.htmlMilo的v?/dc:creator>Milo的v?/author>Thu, 31 Mar 2016 06:06:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/03/31/429913.html http://www.tkk7.com/miaoyachun/comments/429913.html http://www.tkk7.com/miaoyachun/archive/2016/03/31/429913.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/429913.html http://www.tkk7.com/miaoyachun/services/trackbacks/429913.html 2. 详细介绍 http://blog.csdn.net/xhh198781/article/details/10949697 ]]> Spring boot 开启reponse压羃以及部分参数讄 http://www.tkk7.com/miaoyachun/archive/2016/03/29/429861.htmlMilo的v?/dc:creator>Milo的v?/author>Tue, 29 Mar 2016 03:50:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/03/29/429861.html http://www.tkk7.com/miaoyachun/comments/429861.html http://www.tkk7.com/miaoyachun/archive/2016/03/29/429861.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/429861.html http://www.tkk7.com/miaoyachun/services/trackbacks/429861.html server.compression.enabled =true server.compression.mime-types =application/json,application/xml,text/html,text/xml,text/plain server.compression.min-response-size =4096 W一个参数打开压羃开养IW二个参数添加json reponseQ尤其是为rest apiQ?W三个参数是Ҏreponse的大设|启用压~的最?默认?KQ自己根据实际情况调? 参?div>http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#how-to-enable-http-response-compression ]]> 关于java默认的类加蝲器的单代码研I?/title> http://www.tkk7.com/miaoyachun/archive/2016/03/16/429685.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 16 Mar 2016 07:40:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/03/16/429685.html http://www.tkk7.com/miaoyachun/comments/429685.html http://www.tkk7.com/miaoyachun/archive/2016/03/16/429685.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/429685.html http://www.tkk7.com/miaoyachun/services/trackbacks/429685.html 2. 3个加载器q不是真正的父子l承关系Q而是逻辑上的QJVM启动先创建ExtClassloader instanceQ然后构造AppClassloader的时候传入ExtClassloader实例作ؓparent Launcher.ExtClassLoader extcl; try { extcl = Launcher.ExtClassLoader.getExtClassLoader(); } catch (IOException var10) { throw new InternalError( " Could not create extension class loader " , var10); } try { this .loader = Launcher.AppClassLoader.getAppClassLoader(extcl); } catch (IOException var9) { throw new InternalError( " Could not create application class loader " , var9); }
关于双亲委派原理Q?在加载类的时候,会看看parent有没有设定,如果讑֮?p用parent.loadClassҎQ如果没讑֮(==null)也就是parent应该是BootstrapClassloader, 会调用native的findBootstrapClass来加载类Q代码: try { if ( this .parent != null ) { c = this .parent.loadClass(name, false ); } else { c = this .findBootstrapClassOrNull(name); } } catch (ClassNotFoundException var10) { ; }
目的是按照一定优先别装载系l的libQ系lext目录的libQ以及classpath的libQ防止系l的默认行ؓ或者类的实现被修改?br /> 3. java cȝ动态加?br />Java内置的ClassLoaderM在加载一个Class之前查这个Class是否已经被加载过Q已l被加蝲q的Class不会加蝲W二ơ。因此要想重新加载ClassQ我们需要实现自qClassLoader? 另外一个问题是Q每个被加蝲的Class都需要被链接(link)Q这是通过执行ClassLoader.resolve()来实现的Q这个方法是 final的,因此无法重写。Resove()Ҏ不允怸个ClassLoader实例link一个Class两次Q因此,当你需要重新加载一? Class的时候,你需要重新New一个你自己的ClassLoader实例?
]]> 目中用到的一些maven插gȝ http://www.tkk7.com/miaoyachun/archive/2016/01/26/429206.htmlMilo的v?/dc:creator>Milo的v?/author>Tue, 26 Jan 2016 03:41:00 GMT http://www.tkk7.com/miaoyachun/archive/2016/01/26/429206.html http://www.tkk7.com/miaoyachun/comments/429206.html http://www.tkk7.com/miaoyachun/archive/2016/01/26/429206.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/429206.html http://www.tkk7.com/miaoyachun/services/trackbacks/429206.html
maven-shade-plugin 用来打可执行jar包, 可以把所有依赖的三方库都包括q来 exec-maven-plugin 可以执行外部命oQ?nbsp;在项目中对python代码q行~译Q?nbsp;配合maven-assembly-plugin来生成package maven-assembly-plugin 用来构徏目发行包, 要配合xml配置文g来组l包的结构,基本思\是从build环境copy到outputDirectory license-maven-plugin 用来生成目用到?方库的版权汇?nbsp;或者其他的一些用?br />maven-dependency-plugin 用来生成目库之间的依赖关系 appassembler-maven-plugin 可以为项目生成优雅的启动脚本 支持linux/win rpm-maven-plugin 用来为项目构建rpm安装?br />maven-compiler-plugin 指定目的jdk的编译兼容版本以及encodingcd
]]> Idea q程调式遇到使用exec maven 插g不能命中断点的问?/title> http://www.tkk7.com/miaoyachun/archive/2015/10/21/427858.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 21 Oct 2015 09:12:00 GMT http://www.tkk7.com/miaoyachun/archive/2015/10/21/427858.html http://www.tkk7.com/miaoyachun/comments/427858.html http://www.tkk7.com/miaoyachun/archive/2015/10/21/427858.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/427858.html http://www.tkk7.com/miaoyachun/services/trackbacks/427858.html 知道了问题所在解军_Ҏ? 只要修改pom.xml, 然后直接mvn exec:execp正常调式?br /> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>${mvnexec.version}</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <includeProjectDependencies>true</includeProjectDependencies> <executable>java</executable> <workingDirectory>${basedir}/config/sim</workingDirectory> <classpathScope>runtime</classpathScope> <arguments> <argument>-agentlib:jdwp = transport = dt_socket , server = y , suspend = y , address = 4000 </argument> <argument>-classpath</argument> <classpath/> <argument>com.ymiao.Main</argument> <argument>server</argument> <argument>${basedir}/config/sim/sim.yml</argument> </arguments> </configuration> </plugin> </plugins> </build>
ȝ是exec:exec是要独立一个新q程来执行程序的, exec:javaq? 其实用mvnDebug + exec:java也是理论可行?img src ="http://www.tkk7.com/miaoyachun/aggbug/427858.html" width = "1" height = "1" /> ]]> 关于jconsole昄自定义的MBean http://www.tkk7.com/miaoyachun/archive/2015/09/08/427184.htmlMilo的v?/dc:creator>Milo的v?/author>Tue, 08 Sep 2015 02:53:00 GMT http://www.tkk7.com/miaoyachun/archive/2015/09/08/427184.html http://www.tkk7.com/miaoyachun/comments/427184.html http://www.tkk7.com/miaoyachun/archive/2015/09/08/427184.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/427184.html http://www.tkk7.com/miaoyachun/services/trackbacks/427184.html 自定义的Mbean的普通method能在jconsole的Mbeans里显C出来,但是涉及到geters/seters无法显CZ 如果MBean注册C面Ş式创建的MBeanServer在Jconsole上无法显C的MBeanServer server = MBeanServerFactory.createMBeanServer() ;
但是如果注册C面的形式创徏的Server在Jconsole上是可以昄MBean?br />MBeanServer server = ManagementFactory.getPlatformMBeanServer() ;
stackoverflow上也有h发现q个问题
http://stackoverflow.com/questions/7424009/mbeans-registered-to-mbean-server-not-showing-up-in-jconsole
]]> java 帔R池从jdk7开始从ҎUd堆内 http://www.tkk7.com/miaoyachun/archive/2015/05/06/424894.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 06 May 2015 09:35:00 GMT http://www.tkk7.com/miaoyachun/archive/2015/05/06/424894.html http://www.tkk7.com/miaoyachun/comments/424894.html http://www.tkk7.com/miaoyachun/archive/2015/05/06/424894.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/424894.html http://www.tkk7.com/miaoyachun/services/trackbacks/424894.html 从jdk7最开始的release version (http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html)的notes里看?br /> Area: HotSpot Synopsis: In JDK 7, interned strings are no longer allocated in the permanent generation of the Java heap, but are instead allocated in the main part of the Java heap (known as the young and old generations), along with the other objects created by the application. This change will result in more data residing in the main Java heap, and less data in the permanent generation, and thus may require heap sizes to be adjusted. Most applications will see only relatively small differences in heap usage due to this change, but larger applications that load many classes or make heavy use of the String.intern() method will see more significant differences. RFE: 6962931 ]]> Ubuntu12.04s上jenkins用启动脚本启动失败的一U原?/title> http://www.tkk7.com/miaoyachun/archive/2015/02/28/423103.htmlMilo的v?/dc:creator>Milo的v?/author>Sat, 28 Feb 2015 08:51:00 GMT http://www.tkk7.com/miaoyachun/archive/2015/02/28/423103.html http://www.tkk7.com/miaoyachun/comments/423103.html http://www.tkk7.com/miaoyachun/archive/2015/02/28/423103.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/423103.html http://www.tkk7.com/miaoyachun/services/trackbacks/423103.html 今天有同事问Z么ubuntu上启动jenkinsp|Q我记得之前玩的时候ƈ没有出现q种情况Q于是跟t了下,最l错误信息是:daemon: fatal: refusing to execute unsafe program: /usr/bin/java (/opt is group and world writable)
Ҏ原因是机器装了多个版本的jdk, jdk所在的/opt父目录的权限攄比较大,按照daemon要求的限制到755chmod -R 755 /opt
问题p决了?br /> 其实q个场景q是蛮常见的Q遇到的人应该挺多的 ]]> valgrind memory check on java program http://www.tkk7.com/miaoyachun/archive/2013/12/06/407274.htmlMilo的v?/dc:creator>Milo的v?/author>Fri, 06 Dec 2013 02:26:00 GMT http://www.tkk7.com/miaoyachun/archive/2013/12/06/407274.html http://www.tkk7.com/miaoyachun/comments/407274.html http://www.tkk7.com/miaoyachun/archive/2013/12/06/407274.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/407274.html http://www.tkk7.com/miaoyachun/services/trackbacks/407274.html valgrind --error-limit = no --trace-children = yes --smc-check = all --leak-check = full JAVA_CMD
Ҏ写了个有leak的jni函数Q用valgrind成功查出来了
== 31915 == 100 bytes in 1 blocks are definitely lost in loss record 447 of 653 == 31915 == at 0x402CE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) == 31915 == by 0x60424F9: Java_MyJNI_hello (MyJNI.c: 16 )
在老版本valgrind(3.5.0) enable?-trace-children选项后可能出现错?
Error occurred during initialization of VM Unknown x64 processor: SSE2 not supported
升到最新版可以解决q个问题Q升U方法:下蝲src?解压后执?./configure; make; make install
]]> maven本地三方依赖包插件addjars-maven-plugin http://www.tkk7.com/miaoyachun/archive/2013/10/30/405795.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 30 Oct 2013 06:03:00 GMT http://www.tkk7.com/miaoyachun/archive/2013/10/30/405795.html http://www.tkk7.com/miaoyachun/comments/405795.html http://www.tkk7.com/miaoyachun/archive/2013/10/30/405795.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/405795.html http://www.tkk7.com/miaoyachun/services/trackbacks/405795.html < build > < plugins > < plugin > < groupId > com.googlecode.addjars-maven-plugin </ groupId > < artifactId > addjars-maven-plugin </ artifactId > < version > 1.0.2 </ version > < executions > < execution > < goals > < goal > add-jars </ goal > </ goals > < configuration > < resources > < resource > < directory > ${basedir}/../lib </ directory > </ resource > </ resources > </ configuration > </ execution > </ executions > </ plugin > < plugin > < groupId > org.apache.maven.plugins </ groupId > < artifactId > maven-assembly-plugin </ artifactId > < version > ${maven.assembly.version} </ version > < configuration > < descriptorRefs > < descriptorRef > jar-with-dependencies </ descriptorRef > </ descriptorRefs > < appendAssemblyId > false </ appendAssemblyId > </ configuration > < executions > < execution > < phase > package </ phase > < goals > < goal > single </ goal > </ goals > </ execution > </ executions > </ plugin > </ plugins > </ build >
把项目中依赖的三方jars全放到lib目录里,全部会打包到release jar里了 ]]> 反编译java classq优雅的调试 http://www.tkk7.com/miaoyachun/archive/2013/02/22/395575.htmlMilo的v?/dc:creator>Milo的v?/author>Fri, 22 Feb 2013 07:01:00 GMT http://www.tkk7.com/miaoyachun/archive/2013/02/22/395575.html http://www.tkk7.com/miaoyachun/comments/395575.html http://www.tkk7.com/miaoyachun/archive/2013/02/22/395575.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/395575.html http://www.tkk7.com/miaoyachun/services/trackbacks/395575.html 用jd-eclipse 插g来反~译java class文g的输是挺nice的,虽然阅读方便?但是对debug造成一定的困扰Q主要问题是line number的不match. Google了下遇到cM问题的真不少。最l找C解决ҎQ?br />http://sourceforge.net/projects/realignmentjd/files/ -----------------1. Download JD-Eclipse and JD-GUI - http://java.decompiler.free.fr/ and install. 2. Put a file realignment.jd.ide.eclipse_1.0.2.jar in eclipse/plugins directory. To use Realignment feature it is necessary to open the menu Preferences/General/Editors/File Associations and to select "*.class" file type and to choose "Realignment for JD Class File Editor" for Associated editors. Another possibility is the batch realignment after processing JD-GUI. To work properly you must to switch on the property "Display line numbers" in Help/Preferences of JD-GUI. To use this feature it is necessary to open the menu Preferences/Java/Decompiler/Batch Realignment and click button "Open dialog". Existing limitation: the realignment is performed only for the methods. To work properly it is necessary that the property "Display line numbers" in menu "Preferences/Java/Decompiler" was active.
JD-Eclipse插g + realignment 补丁让优雅的debug class 文g成ؓ可能?br /> 如果只是Z阅读class代码Q徏议不要用realignment 补丁Q这样会降低代码的可L(会多出大量的IQ?br /> ]]> 一些项目中用到的mvn例子 http://www.tkk7.com/miaoyachun/archive/2013/01/10/394058.htmlMilo的v?/dc:creator>Milo的v?/author>Thu, 10 Jan 2013 05:33:00 GMT http://www.tkk7.com/miaoyachun/archive/2013/01/10/394058.html http://www.tkk7.com/miaoyachun/comments/394058.html http://www.tkk7.com/miaoyachun/archive/2013/01/10/394058.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/394058.html http://www.tkk7.com/miaoyachun/services/trackbacks/394058.html mvn 执行外部命o 命o行模?br />mvn exec:exec -Dexec.executable = sh -Dexec.workingdir = ./bin -Dexec.args = hello.sh
配置文g形式 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <id>test-exec</id> <phase>initialize</phase> <configuration> <executable>sh</executable> <workingDirectory>./bin</workingDirectory> <arguments> <argument>hello.sh</argument> </arguments> </configuration> <goals> <goal>exec</goal> </goals> </execution> </executions> </plugin>
mvn 生成java目 生成骨架mvn archetype:generate -DgroupId = com.abc.product -DartifactId = product -DpackageName = com.abc.product -DarchetypeArtifactId = maven-archetype-quickstart
转成eclipse能识别的java 目mvn eclipse:eclipse
导入eclipse 然后coding mvnq行单元试 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version> 2.12.4 </version> <configuration> <forkMode>pertest</forkMode> <excludes> <exclude>**/perftest/*.java</exclude> </excludes> <systemProperties> <property> <name>log4j.configuration</name> <value>target/test-classes/log4j.properties</value> </property> </systemProperties> </configuration> </plugin>
mvnq行code coveragel计 <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0-alpha-3</version> <inherited>true</inherited> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>surefire-report-maven-plugin</artifactId> <inherited>true</inherited> </plugin> </plugins> </reporting>
mvn生成javadoc <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version> 2.9 </version> <configuration> <show>private</show> </configuration> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>javadoc</goal> <goal>test-javadoc</goal> </goals> <phase>site</phase> </execution> </executions> </plugin>
]]> 关于java.library.path http://www.tkk7.com/miaoyachun/archive/2012/12/06/392529.htmlMilo的v?/dc:creator>Milo的v?/author>Thu, 06 Dec 2012 03:05:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/12/06/392529.html http://www.tkk7.com/miaoyachun/comments/392529.html http://www.tkk7.com/miaoyachun/archive/2012/12/06/392529.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/392529.html http://www.tkk7.com/miaoyachun/services/trackbacks/392529.html 最q项目要用JNI, 涉及到用java.library.pathq个参数Q开始以为只要ldconfig能识别到的so文gjava 一定能扑ֈQ可惜ƈ不是q样。?br />要想javaE序扑ֈ׃n库还是要在执行javaE序的时候指定java.library.pathQ用eclipse的话可以讄如下Q?br />
Properties->Run/Debug settings->Arguments->VM arguments ----------------------------------------- -Djava.library.path=/home/miaoyachun/workspace/JNIC/Release
q个是传l的方式Qgoogle了下有个tricky的方式让E序动态修改java.library.path private static void loadJNILibDynamically() { try { System.setProperty( " java.library.path " , System.getProperty( " java.library.path " ) + " :/home/miaoyachun/workspace/JNIC/Release/ " ); Field fieldSysPath = ClassLoader. class .getDeclaredField( " sys_paths " ); fieldSysPath.setAccessible( true ); fieldSysPath.set( null , null ); System.loadLibrary( " JNIC " ); } catch (Exception e) { // do nothing for exception } }
事实上linux下还有个环境变量LD_LIBRARY_PATHQ如果lib能在q个path里找刎ͼjava.library.path׃用配|了Q而且不需要关心lib之间依赖的问题。java.library.path在这斚w弱很多Q比如lib依赖其他目录的lib{?img src ="http://www.tkk7.com/miaoyachun/aggbug/392529.html" width = "1" height = "1" /> ]]> Ubuntu上的alternatives http://www.tkk7.com/miaoyachun/archive/2012/10/26/390260.htmlMilo的v?/dc:creator>Milo的v?/author>Fri, 26 Oct 2012 05:31:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/10/26/390260.html http://www.tkk7.com/miaoyachun/comments/390260.html http://www.tkk7.com/miaoyachun/archive/2012/10/26/390260.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/390260.html http://www.tkk7.com/miaoyachun/services/trackbacks/390260.html 关于alternatives 的用?br /> alternatives --install /usr/bin/java java /opt/jdk1.5 .0_ 22 /bin/java 15000 alternatives --install /usr/bin/javac javac /opt/jdk1.5 .0_ 22 /bin/javac 15000 alternatives --config java alternatives --config javac
最q切换桌面环境到ubuntu, 发现alternatives q个工具改名?update-alternatives 用法q是一L。?br /> ]]> 用JNI从C传递结构体到JAVA http://www.tkk7.com/miaoyachun/archive/2012/10/12/389473.htmlMilo的v?/dc:creator>Milo的v?/author>Fri, 12 Oct 2012 08:40:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/10/12/389473.html http://www.tkk7.com/miaoyachun/comments/389473.html http://www.tkk7.com/miaoyachun/archive/2012/10/12/389473.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/389473.html http://www.tkk7.com/miaoyachun/services/trackbacks/389473.html 直接上C的实?br />typedef struct Foo { int len; char name[ 100 ]; } Foo_t; JNIEXPORT jint JNICALL Java_TestJNI_foo(JNIEnv * env, jobject obj, jobject fooObj) { Foo_t * bar = malloc( sizeof (Foo_t)); jclass clazz; jfieldID fid; // init the bar data of C strcpy(bar -> name, " Yachun Miao " ); bar -> len = strlen(bar -> name); // mapping bar of C to foo clazz = ( * env) -> GetObjectClass(env, fooObj); if ( 0 == clazz) { printf( " GetObjectClass returned 0\n " ); return ( - 1 ); } fid = ( * env) -> GetFieldID(env, clazz, " len " , " I " ); ( * env) -> SetLongField(env, fooObj, fid, bar -> len); fid = ( * env) -> GetFieldID(env, clazz, " name " , " Ljava/lang/String; " ); jstring name = ( * env) -> NewStringUTF(env, bar -> name); ( * env) -> SetObjectField(env, fooObj, fid, name); free(bar); return 0 ; }
对应的Java调用public class Foo { protected int len; protected String name; } private static native int foo(Foo fooObj); public static void main(String args[]) { System.loadLibrary( " mylib " ); Foo foo = new Foo(); foo(foo); System.out.println(foo.name); System.out.println(foo.len); } 参考链?br />http://www.steveolyo.com/JNI/JNI.html#CSTRCJ
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html
]]> Jetty SslSelectChannelConnector about file downloading http://www.tkk7.com/miaoyachun/archive/2012/07/18/383427.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 18 Jul 2012 10:22:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/07/18/383427.html http://www.tkk7.com/miaoyachun/comments/383427.html http://www.tkk7.com/miaoyachun/archive/2012/07/18/383427.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/383427.html http://www.tkk7.com/miaoyachun/services/trackbacks/383427.html 发现用curl从jetty服务器上download文g的速度比较慢大概只?M/s, 开始以为curl有默认的limit-rateQ设|ؓ1G以后发现q是慢?br />然后开始怀疑是jetty server的问题。看SslSelectChannelConnector的responseBufferSize比较像,反复实验发现原来是由于headerBufferSize太小?br /> 改ؓ32K以后Q?br /> SslSelectChannelConnector connector = new SslSelectChannelConnector(); connector.setRequestBufferSize( 32768 ); 效果Q?br />curl -k https://USER:PASSWD@HOST:PORT/api/internal/file?filename = /path/to/file > /dest/to/file % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 723M 100 723M 0 0 29 .3M 0 0 : 00 : 24 0 : 00 : 24 --:--:-- 29 .4M
ref: http://wiki.eclipse.org/Jetty/Howto/Configure_Connectors ]]> maven project to eclipse java project http://www.tkk7.com/miaoyachun/archive/2012/06/27/381618.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 27 Jun 2012 07:56:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/06/27/381618.html http://www.tkk7.com/miaoyachun/comments/381618.html http://www.tkk7.com/miaoyachun/archive/2012/06/27/381618.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/381618.html http://www.tkk7.com/miaoyachun/services/trackbacks/381618.html steps: 1 . download maven project src code 2 . cd project root dir & run " mvn eclipse:eclipse " 3 . import it as eclipse java prject
step2 will generate .classpath & .project file ]]> 目依赖分析工具 http://www.tkk7.com/miaoyachun/archive/2012/06/13/380695.htmlMilo的v?/dc:creator>Milo的v?/author>Wed, 13 Jun 2012 08:13:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/06/13/380695.html http://www.tkk7.com/miaoyachun/comments/380695.html http://www.tkk7.com/miaoyachun/archive/2012/06/13/380695.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/380695.html http://www.tkk7.com/miaoyachun/services/trackbacks/380695.html JBoss Tattletale is a tool that can help you get an overview of the project you are working on or a product that you depend on. The tool will provide you with reports that can help you * Identify dependencies between JAR files * Find missing classes from the classpath * Spot if a class/package is located in multiple JAR files * Spot if the same JAR file is located in multiple locations * With a list of what each JAR file requires and provides * Verify the SerialVersionUID of a class * Find similar JAR files that have different version numbers * Find JAR files without a version number * Find unused JAR files * Identify sealed / signed JAR archives * Locate a class in a JAR file * Get the OSGi status of your project
使用Ҏjava -Xmx512m -jar tattletale.jar [ -exclude=<excludes> ] <scan-directory> [ output-directory ]
注意事项tattletale只分析jar包之间的依赖Q需要自己把所有的class文g打包攑օscan-directoryQ然后把依赖的lib也放入同个目?/span>
]]> Javaq程memory leak分析 http://www.tkk7.com/miaoyachun/archive/2012/03/16/372005.htmlMilo的v?/dc:creator>Milo的v?/author>Fri, 16 Mar 2012 01:45:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/03/16/372005.html http://www.tkk7.com/miaoyachun/comments/372005.html http://www.tkk7.com/miaoyachun/archive/2012/03/16/372005.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/372005.html http://www.tkk7.com/miaoyachun/services/trackbacks/372005.html jmap & jhat 通过分析heap中对象的数量q有大小可以定位哪个cd了问题?img src ="http://www.tkk7.com/miaoyachun/aggbug/372005.html" width = "1" height = "1" /> ]]> Program exception handling http://www.tkk7.com/miaoyachun/archive/2012/03/12/371745.htmlMilo的v?/dc:creator>Milo的v?/author>Mon, 12 Mar 2012 08:35:00 GMT http://www.tkk7.com/miaoyachun/archive/2012/03/12/371745.html http://www.tkk7.com/miaoyachun/comments/371745.html http://www.tkk7.com/miaoyachun/archive/2012/03/12/371745.html#Feedback 0 http://www.tkk7.com/miaoyachun/comments/commentRss/371745.html http://www.tkk7.com/miaoyachun/services/trackbacks/371745.html 异常是有代h的,比如量避免使用异常来实现流E控?br />2. 量处理异常 有能力处理异常则处理掉,不然外层函数会篏U太多的异常 3. 处理不了则抛出异?br /> 自己问自己,q个异常能够处理么,不行的话直接抛出Q可以参考原? 4. Throw early and catch late 一般底层函C会处理异常,外层函数会根据上下文捕获异常q行处理或者{?br />5. 不要覆盖异常 6. try块不应该太大Q代码规范) 7. 函数抛出的异怸应该太多Q代码规范) 参?br />