paulwong

2019年8月1日 #

Guide to the Most Important JVM Parameters

https://www.baeldung.com/jvm-parametersa

Optimising Your Minecraft: Jvm Arguments
https://xealgaming.net/threads/optimising-your-minecraft-jvm-arguments.4758/

posted @ 2019-08-01 16:55 paulwong 閱讀(19) | 評論 (0)編輯 收藏

JVM內存配置

JVM內存主要分為兩個部分,分別是PermanentSapce和HeapSpace。

PermantSpace主要負責存放加載的Class類級對象如class本身,method,field等反射對象,一般不用配置。

JVM的Heap區可以通過-X參數來設定。HeapSpace= {Old + NEW {= Eden , from, to } }

當一個URL被訪問時,內存申請過程如下:

  1. JVM會試圖為相關Java對象在Eden中初始化一塊內存區域 
  2. 當Eden空間足夠時,內存申請結束。否則到下一步 
  3. JVM試圖釋放在Eden中所有不活躍的對象(這屬于1或更高級的垃圾回收), 釋放后若Eden空間仍然不足以放入新對象,則試圖將部分Eden中活躍對象放入Survivor區
  4.  Survivor區被用來作為Eden及OLD的中間交換區域,當OLD區空間足夠時,Survivor區的對象會被移到Old區,否則會被保留在Survivor區 
  5. 當OLD區空間不夠時,JVM會在OLD區進行完全的垃圾收集(0級) 
  6. 完全垃圾收集后,若Survivor及OLD區仍然無法存放從Eden復制過來的部分對象,導致JVM無法在Eden區為新對象創建內存區域,則出現”out of memory錯誤”

Xms/Xmx:定義NEW+OLD段的總尺寸,ms為JVM啟動時NEW+OLD的內存大小;mx為最大可占用的NEW+OLD內存大小。。在用戶生產環境上一般將這兩個值設為相同,以減少運行期間系統在內存申請上所花的開銷; 

NewSize/MaxNewSize:定義單獨NEW段的尺寸,NewSize為JVM啟動時NEW的內存大小;MaxNewSize為最大可占用的NEW的內存大小。在用戶生產環境上一般將這兩個值設為相同,以減少運行期間系統在內存申請上所花的開銷;

Xms/Xmx和NewSize/MaxNewSize定義好后,OLD區間也自然定義完畢了,即OLD區初始大小=(Xms-NewSize),OLD區最大可占用大小=(Xmx-MaxNewSize); 

PermSize/MaxPermSize:定義Perm段的尺寸,PermSize為JVM啟動時Perm的內存大小;MaxPermSize為最大可占用的Perm內存大小。在用戶生產環境上一般將這兩個值設為相同,以減少運行期間系統在內存申請上所花的開銷。

posted @ 2019-08-01 16:44 paulwong 閱讀(37) | 評論 (0)編輯 收藏

使用 Awaitility 測試異步代碼

自動化工具 異步校驗工具 awaitility 快速入門
https://testerhome.com/topics/7408


https://yanbin.blog/test-asyn-call-with-awaitility/

Introduction to Awaitlity
https://www.baeldung.com/awaitlity-testing




posted @ 2019-08-01 10:06 paulwong 閱讀(22) | 評論 (0)編輯 收藏

2019年7月31日 #

Spring Batch JUnit test for multiple jobs


https://stackoverflow.com/questions/34217101/spring-batch-junit-test-for-multiple-jobs

@Configuration
public class TestBatchConfiguration implements MergedBeanDefinitionPostProcessor {

    @Autowired
    @Qualifier("JobA")
    private Job job;

    @Bean(name="jtestl")
    public JobLauncherTestUtils jobLauncherTestUtils() {
        JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
        jobLauncherTestUtils.setJob(job);
        return jobLauncherTestUtils;
    }

    /**
     * 
https://stackoverflow.com/questions/22416140/autowire-setter-override-with-java-config
     * This is needed to inject the correct job into JobLauncherTestUtils
     
*/
    @Override
    public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
        if(beanName.equals("jtestl")) {
            beanDefinition.getPropertyValues().add("job", getMyBeanFirstAImpl());
        }
    }

    private Object getMyBeanFirstAImpl() {
        return job;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}

posted @ 2019-07-31 10:48 paulwong 閱讀(27) | 評論 (0)編輯 收藏

2019年7月30日 #

Keep SSH session alive

sshd (the server) closes the connection if it doesn't hear anything from the client for a while. You can tell your client to send a sign-of-life signal to the server once in a while.

The configuration for this is in the file "~/.ssh/config", create it if the configuration file does not exist. To send the signal every four minutes (240 seconds) to the remote host, put the following in your "~/.ssh/config" file.

Host remotehost:     HostName remotehost.com     ServerAliveInterval 240 

This is what I have in my "~/.ssh/config":

To enable it for all hosts use:

Host * ServerAliveInterval 240 

Also make sure to run:

chmod 600 ~/.ssh/config 

because the config file must not be world-readable.

posted @ 2019-07-30 13:46 paulwong 閱讀(23) | 評論 (0)編輯 收藏

2019年7月25日 #

publish over ssh 實現 Jenkins 遠程部署

Jenkins遠程部署,一開始沒有任何頭緒,想了很多方案. 因為兩臺機器都是windows系統,所以想到publish over cifs, 但是這個網上資料太少,貌似只能內網使用。又想到了Jenkins 分布式構建,但是Jenkins構建的代碼和產物最后自動拷貝到主節點。而遠程機器其實是客戶方的機器,所以這個分布式構建并不適用。最后還是選定publish over ssh來實現遠程部署。 
請注意:在進行遠程部署操作前,先要確保客戶機能ssh 登錄到遠程機器。如果不知道SSH怎么登陸,請參考http://blog.csdn.net/flyingshuai/article/details/72897692 
1. 安裝publish over ssh 插件,安裝很簡單,在此不表。 
2. 在Jenkins系統設置里找到Publish over SSH模塊 
3. 用戶名/密碼方式登錄的,系統設置里設置如下: 
4. 如果是證書登錄的,系統設置里設置如下: 
5. Job設置,點擊增加構建后操作步驟,選擇send build artifacts over ssh, 設置如下: 
6. 文件上傳到遠程服務器后,還有一些后續操作,比如,替換數據庫配置文件。可以把bat命令寫到一個批處理文件中,存到服務器上。Exec command填寫批處理文件的絕對路徑。如上圖所示。
關于bat腳本: 
如果每次都需要替換同樣的文件,用copy /y 是無條件覆蓋,不會詢問。而xcopy可以實現批量拷貝文件和文件夾。如果文件較多可用此命令 
注意腳本運行失敗,構建也會顯示藍色成功圖標,所以一定要打開控制臺輸出,看是否真的成功。
--------------------- 
作者:flyingshuai 
來源:CSDN 
原文:https://blog.csdn.net/flyingshuai/article/details/72898665 
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

posted @ 2019-07-25 09:33 paulwong 閱讀(40) | 評論 (0)編輯 收藏

2019年7月24日 #

How do I clear my Jenkins/Hudson build history?

     摘要: 問題:I recently updated the configuration of one of my hudson builds. The build history is out of sync. Is there a way to clear my build history?Please and thank you回答1:If you click Manage Hudson / Relo...  閱讀全文

posted @ 2019-07-24 16:18 paulwong 閱讀(28) | 評論 (0)編輯 收藏

Springboot ActiveMQ jmsTemplate配置

@Configuration
@DependsOn(value="cachingConnectionFactory")
public class JmsTemplateConfiguration {

@Value("${wechat.sendmessage.queue}")
private String queueName;

@Value("${wechat.sendmessage.topic}")
private String topicName;

@Value("${spring.jms.pub-sub-domain}")
private boolean isPubSubDomain;


/**
 * 定義點對點隊列
 * 
@return
 
*/
@Bean
public Queue queue() {
    return new ActiveMQQueue(queueName);
}



/**
 * 定義一個主題
 * 
@return
 
*/
@Bean
public Topic topic() {
    return new ActiveMQTopic(topicName);
}

private final ObjectProvider<DestinationResolver> destinationResolver;
private final ObjectProvider<MessageConverter> messageConverter;
private final CachingConnectionFactory cachingConnectionFactory;

@Autowired
public JmsTemplateConfiguration(ObjectProvider<DestinationResolver> destinationResolver,
                                ObjectProvider<MessageConverter> messageConverter,
                                CachingConnectionFactory cachingConnectionFactory) {
    this.destinationResolver = destinationResolver;
    this.messageConverter = messageConverter;
    this.cachingConnectionFactory = cachingConnectionFactory;
}

/**
 * 配置隊列生產者的JmsTemplate
 * 
@return JmsTemplate
 
*/
@Bean(name="jmsQueueTemplate")
public JmsTemplate jmsQueueTemplate() {
    //設置創建連接的工廠
    
//JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    
//優化連接工廠,這里應用緩存池 連接工廠就即可
    JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
    //設置默認消費topic
   
//jmsTemplate.setDefaultDestination(topic());
    
//設置P2P隊列消息類型
    jmsTemplate.setPubSubDomain(isPubSubDomain);

    DestinationResolver destinationResolver = (DestinationResolver) this.destinationResolver.getIfUnique();
    if (destinationResolver != null) {
        jmsTemplate.setDestinationResolver(destinationResolver);
    }
    MessageConverter messageConverter = (MessageConverter) this.messageConverter.getIfUnique();
    if (messageConverter != null) {
        jmsTemplate.setMessageConverter(messageConverter);
    }
    //deliveryMode, priority, timeToLive 的開關,要生效,必須配置為true,默認false
    jmsTemplate.setExplicitQosEnabled(true);
    //DeliveryMode.NON_PERSISTENT=1:非持久 ; DeliveryMode.PERSISTENT=2:持久
    
//定義持久化后節點掛掉以后,重啟可以繼續消費.
    jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);
    //默認不開啟事務
    System.out.println("默認是否開啟事務:"+jmsTemplate.isSessionTransacted());
    //如果不啟用事務,則會導致XA事務失效;
    
//作為生產者如果需要支持事務,則需要配置SessionTransacted為true
  
//jmsTemplate.setSessionTransacted(true);
    
//消息的應答方式,需要手動確認,此時SessionTransacted必須被設置為false,且為Session.CLIENT_ACKNOWLEDGE模式
    
//Session.AUTO_ACKNOWLEDGE  消息自動簽收
    
//Session.CLIENT_ACKNOWLEDGE  客戶端調用acknowledge方法手動簽收
    
//Session.DUPS_OK_ACKNOWLEDGE 不必必須簽收,消息可能會重復發送
    jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    return jmsTemplate;
}

/**
 * 配置發布訂閱生產者的JmsTemplate
 * 
@return JmsTemplate
 
*/
@Bean(name="jmsTopicTemplate")
public JmsTemplate jmsTopicTemplate() {
    //設置創建連接的工廠
   
//JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    
//優化連接工廠,這里應用緩存池 連接工廠就即可
    JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
    //設置默認消費topic
  
//jmsTemplate.setDefaultDestination(topic());
    
//設置發布訂閱消息類型
    jmsTemplate.setPubSubDomain(isPubSubDomain);


    //deliveryMode, priority, timeToLive 的開關,要生效,必須配置為true,默認false
    jmsTemplate.setExplicitQosEnabled(true);
    //DeliveryMode.NON_PERSISTENT=1:非持久 ; DeliveryMode.PERSISTENT=2:持久
    jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);

    //默認不開啟事務
    System.out.println("是否開啟事務"+jmsTemplate.isSessionTransacted());
    //如果session帶有事務,并且事務成功提交,則消息被自動簽收。如果事務回滾,則消息會被再次傳送。
    
//jmsTemplate.setSessionTransacted(true);

    
//不帶事務的session的簽收方式,取決于session的配置。
    
//默認消息確認方式為1,即AUTO_ACKNOWLEDGE
    System.out.println("是否消息確認方式"+jmsTemplate.getSessionAcknowledgeMode());

    //消息的應答方式,需要手動確認,此時SessionTransacted必須被設置為false,且為Session.CLIENT_ACKNOWLEDGE模式
    
//Session.AUTO_ACKNOWLEDGE  消息自動簽收
    
//Session.CLIENT_ACKNOWLEDGE  客戶端調用acknowledge方法手動簽收
    
//Session.DUPS_OK_ACKNOWLEDGE 不必必須簽收,消息可能會重復發送
    jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);

    return jmsTemplate;
}

}

posted @ 2019-07-24 11:40 paulwong 閱讀(46) | 評論 (0)編輯 收藏

2019年7月18日 #

Enterprise Integration Patterns

Why Enterprise Integration Patterns?

Enterprise integration is too complex to be solved with a simple 'cookbook' approach. Instead, patterns can provide guidance by documenting the kind of experience that usually lives only in architects' heads: they are accepted solutions to recurring problems within a given context. Patterns are abstract enough to apply to most integration technologies, but specific enough to provide hands-on guidance to designers and architects. Patterns also provide a vocabulary for developers to efficiently describe their solution.

Patterns are not 'invented'; they are harvested from repeated use in practice. If you have built integration solutions, it is likely that you have used some of these patterns, maybe in slight variations and maybe calling them by a different name. The purpose of this site is not to "invent" new approaches, but to present a coherent collection of relevant and proven patterns, which in total form an integration pattern language.

Despite the 700+ pages, our book covers only a fraction of patterns (and the problems to be solved) in the integration space. The current patterns focus on Messaging, which forms the basis of most other integration patterns. We have started to harvest more patterns but are realizing (once again) how much work documenting these patterns really is. So please stay tuned.

Messaging Patterns

We have documented 65 messaging patterns, organized as follows:

Message Construct.
Message
Command Message
Document Message
Event Message
Request-Reply
Return Address
Correlation Identifier
Message Sequence
Message Expiration
Format Indicator
Message Routing
Pipes-and-Filters
Message Router
Content-based Router
Message Filter
Dynamic Router
Recipient List
Splitter
Aggregator
Resequencer
Composed Msg. Processor
Scatter-Gather
Routing Slip
Process Manager
Message Broker
Message
Transformation
Message Translator
Envelope Wrapper
Content Enricher
Content Filter
Claim Check
Normalizer
Canonical Data Model
Messaging Endpoints
Message Endpoint
Messaging Gateway
Messaging Mapper
Transactional Client
Polling Consumer
Event-driven Consumer
Competing Consumers
Message Dispatcher
Selective Consumer
Durable Subscriber
Idempotent Receiver
Service Activator
Messaging Channels
Message Channel
Point-to-Point Channel
Publish-Subscr. Channel
Datatype Channel
Invalid Message Channel
Dead Letter Channel
Guaranteed Delivery
Channel Adapter
Messaging Bridge
Message Bus
Systems Mgmt.
Control Bus
Detour
Wire Tap
Message History
Message Store
Smart Proxy
Test Message
Channel Purger


https://www.enterpriseintegrationpatterns.com/patterns/messaging/index.html

posted @ 2019-07-18 14:11 paulwong 閱讀(32) | 評論 (0)編輯 收藏

SPRING BATCH & SPRING INTEGRATION TUTORIAL

Spring JMS Artemis Example 6 minute read

A detailed step-by-step tutorial on how to connect to Apache ActiveMQ Artemis using Spring JMS and Spring Boot.

Spring JMS Topic Example 5 minute read

A detailed step-by-step tutorial on how to publish/subscribe to a JMS topic using Spring JMS and Spring Boot.

Spring JMS Integration Example12 minute read

A detailed step-by-step tutorial on how to connect to an ActiveMQ JMS broker using Spring Integration and Spring Boot.

Spring JMS Listener Example 7 minute read

A detailed step-by-step tutorial on how a Spring JMS listener works in combination with Spring Boot.

Spring JMS JmsTemplate Example 7 minute read

A detailed step-by-step tutorial on how to use JmsTemplate in combination with Spring JMS and Spring Boot.

Spring JMS Message Converter Example5 minute read

A detailed step-by-step tutorial on how to implement a message converter using Spring JMS and Spring Boot.

Spring Batch Admin Example 11 minute read

A detailed step-by-step tutorial on how to use a Spring Boot admin UI to manage Spring Batch jobs.

Spring Batch Example 11 minute read

A detailed step-by-step tutorial on how to implement a Hello World Spring Batch job using Spring Boot.

posted @ 2019-07-18 13:21 paulwong 閱讀(33) | 評論 (0)編輯 收藏

僅列出標題  下一頁
魔法糖果闯关