添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
礼貌的针织衫  ·  Java8函数之旅 (八) - ...·  9 月前    · 
寂寞的手术刀  ·  reactjs - Error: ...·  1 年前    · 
Partner – Bellsoft – NPI EA (cat = Spring/DevOps)
announcement - icon

30% less RAM and a 30% smaller base image for running a Spring Boot application? Yes, please.

Alpaquita Linux was designed to efficiently run containerized Java applications.

It's meant to handle heavy workloads and do it well.

And the Alpaquita Containers incorporates Liberica JDK Lite, a Java runtime tailored to cloud-based services:

Alpaquita Containers now.

Partner – Digma – NPI EA (tag = Debugging)
announcement - icon

Repeatedly, code that works in dev breaks down in production. Java performance issues are difficult to track down or predict.

Simply put, Digma provides immediate code feedback . As an IDE plugin, it identifies issues with your code as it is currently running in test and prod.

The feedback is available from the minute you are writing

Imagine being alerted to any regression or code smell as you're running and debugging locally. Also, identifying weak spots that need attending to, based on integration testing results.

>> Enable code feedback in your IDE.

Of course, Digma is free for developers.

Partner – MongoDB – NPI EA (cat = NoSQL)
announcement - icon

>> Learn all about Field Level Encryption on the client-side with MongoDB

An interesting read.

As always, the writeup is super practical and based on a simple application that can work with documents with a mix of encrypted and unencrypted fields.

Partner – Lightrun – NPI EA (cat=Spring)

We rely on other people’s code in our own work. Every

It might be the language you’re writing in, the framework you’re building on, or some esoteric piece of software that does one thing so well you never found the need to implement it yourself.

The problem is, of course, when things fall apart in production - debugging the implementation of a 3rd party library you have no intimate knowledge of is, to say the least, tricky.

Lightrun is a new kind of debugger.

It's one geared specifically towards real-life production environments. Using Lightrun, you can drill down into running applications, including 3rd party dependencies, with real-time logs, snapshots, and metrics.

Learn more in this quick, 5-minute Lightrun tutorial :

Essential List of Spring Boot Annotations and Their Use Cases

Partner – AEGIK AB – NPI EA (tag = SQL)
announcement - icon

Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.

The Jet Profiler was built for MySQL only , so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.

Critically, it has very minimal impact on your server's performance, with most of the profiling work done separately - so it needs no server changes, agents or separate services.

Basically, you install the desktop application, connect to your MySQL server , hit the record button, and you'll have results within minutes:

out the Profiler

Partner – DBSchema – NPI EA (tag = SQL)
announcement - icon

DbSchema is a super-flexible database designer, which can take you from designing the DB with your team all the way to safely deploying the schema .

The way it does all of that is by using a design model , a database-independent image of the schema, which can be shared in a team using GIT and compared or deployed on to any database.

And, of course, it can be heavily visual, allowing you to interact with the database using diagrams, visually compose queries, explore the data, generate random data, import data or build HTML5 database reports.

Take a look at DBSchema

Course – LS (cat=Java)

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

> CHECK OUT THE COURSE

1. Overview

In our previous Activiti with Java intro article, we saw the importance of the ProcessEngine and created one via the default static API provided by the framework.

Beyond the default, there are other ways of creating a ProcessEngine – which we'll explore here.

2. Obtaining a ProcessEngine Instance

There are two ways of getting an instance of ProcessEngine :

  • using the ProcessEngines class
  • programmatically, via the ProcessEngineConfiguration
  • Let's take a closer look at examples for both of these approaches.

    3. Get ProcessEngine Using ProcessEngines Class

    Typically, the ProcessEngine is configured using an XML file called activiti.cfg.xml, with is what the default creation process will use as well.

    Here's a quick example of what this configuration can look like:

    <beans xmlns="...">
        <bean id="processEngineConfiguration" class=
          "org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
            <property name="jdbcUrl"
              vasentence you have mentioned and also changed thelue="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
            <property name="jdbcDriver" value="org.h2.Driver" />
            <property name="jdbcUsername" value="root" />
            <property name="jdbcPassword" value="" />
            <property name="databaseSchemaUpdate" value="true" />
        </bean>
    </beans>

    Notice how the persistence aspect of the engine is configured here.

    And now, we can obtain the ProcessEngine :

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    4. Get ProcessEngine Using ProcessEngineConfiguration

    Moving past the default route of obtaining the engine – there are two ways of creating the ProcessEngineConfiguration :

  • Using XML Config
  • Using Java Config
  • Let's start with XML configuration.

    As mentioned in section 2.1. – we can define the ProcessEngineConfiguration programmatically, and build the ProcessEngine using that instance:

    @Test 
    public void givenXMLConfig_whenCreateDefaultConfiguration_thenGotProcessEngine() {
        ProcessEngineConfiguration processEngineConfiguration 
          = ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResourceDefault();
        ProcessEngine processEngine 
          = processEngineConfiguration.buildProcessEngine();
        assertNotNull(processEngine);
        assertEquals("root", processEngine.getProcessEngineConfiguration()
          .getJdbcUsername());
    

    The method createProcessEngineConfigurationFromResourceDefault() will also look for the activiti.cfg.xml file, and now we only need to call the buildProcessEngine() API.

    In this case, the default bean name it looks for is processEngineConfiguration. If we want to change the config file name or the bean name, we can use other available methods for creating the ProcessEngineConfiguration.

    Let's have a look at a few examples.

    First, we'll change the configuration file name and ask the API to use our custom file:

    @Test 
    public void givenDifferentNameXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
        ProcessEngineConfiguration processEngineConfiguration 
          = ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource(
              "my.activiti.cfg.xml");
        ProcessEngine processEngine = processEngineConfiguration
          .buildProcessEngine();
        assertNotNull(processEngine);
        assertEquals("baeldung", processEngine.getProcessEngineConfiguration()
          .getJdbcUsername());
    

    Now, let's also change the bean name:

    @Test 
    public void givenDifferentBeanNameInXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
        ProcessEngineConfiguration processEngineConfiguration 
          = ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource(
              "my.activiti.cfg.xml", 
              "myProcessEngineConfiguration");
        ProcessEngine processEngine = processEngineConfiguration
          .buildProcessEngine();
        assertNotNull(processEngine);
        assertEquals("baeldung", processEngine.getProcessEngineConfiguration()
          .getJdbcUsername());
    

    Of course, now that the configuration is expecting different names, we need to change the filename (and the bean name) to match – before running the test.

    Other available options to create the engine are createProcessEngineConfigurationFromInputStream(InputStream inputStream),
    createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName).

    If we don't want to use XML config, we can also set things up using Java config only.

    We're going to work with four different classes; each of these represents a different environment:

  • org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration – the ProcessEngine is used in a standalone way, backed by the DB
  • org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration – by default, an H2 in-memory database is used. The DB is created and dropped when the engine starts and shuts down – hence, this configuration style can be used for testing
  • org.activiti.spring.SpringProcessEngineConfiguration – to be used in Spring environment
  • org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration – the engine runs in standalone mode, with JTA transactions
  • Let's take a look at a few examples.

    Here is a JUnit test for creating a standalone process engine configuration:

    @Test 
    public void givenNoXMLConfig_whenCreateProcessEngineConfig_thenCreated() {
        ProcessEngineConfiguration processEngineConfiguration 
          = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration();
        ProcessEngine processEngine = processEngineConfiguration
          .setDatabaseSchemaUpdate(ProcessEngineConfiguration
            .DB_SCHEMA_UPDATE_TRUE)
          .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
          .buildProcessEngine();
        assertNotNull(processEngine);
        assertEquals("sa", processEngine.getProcessEngineConfiguration()
          .getJdbcUsername());
    

    Similarly, we'll write a JUnit test case for creating the standalone process engine configuration using the in-memory database:

    @Test 
    public void givenNoXMLConfig_whenCreateInMemProcessEngineConfig_thenCreated() {
        ProcessEngineConfiguration processEngineConfiguration 
          = ProcessEngineConfiguration
          .createStandaloneInMemProcessEngineConfiguration();
        ProcessEngine processEngine = processEngineConfiguration
          .buildProcessEngine();
        assertNotNull(processEngine);
        assertEquals("sa", processEngine.getProcessEngineConfiguration()
          .getJdbcUsername());
    

    5. Database Setup

    By default, Activiti API will use the H2 in-memory database, with database name “activiti” and username “sa”.

    If we need to use any other database, we'll have to set things up explicitly – using two main properties.

    databaseType – valid values are h2, mysql, oracle, postgres, mssql, db2. This can also be figured out from the DB configuration but will be useful if automatic detection fails.

    databaseSchemaUpdate – this property allows us to define what happens to the database when the engine boots up or shuts down. It can have these three values:

  • false (default) – this option validates the version of database schema against the library. The engine will throw an exception if they do not match
  • true – when the process engine configuration is built, a check is performed on the database. The database will be created/updated create-drop accordingly
  • ” – this will create the DB schema when the process engine is created and will drop it when the process engine shuts down.
  • We can define the DB configuration as JDBC properties:

    <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
    <property name="jdbcDriver" value="org.h2.Driver" />
    <property name="jdbcUsername" value="sa" />
    <property name="jdbcPassword" value="" />
    <property name="databaseType" value="mysql" />
    

    Alternatively, if we are using DataSource:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
        <property name="username" value="activiti" />
        <property name="password" value="activiti" />
        <property name="defaultAutoCommit" value="false" />
        <property name="databaseType" value="mysql" />
    </bean>
    

    6. Conclusion

    In this quick tutorial, we focused on several different ways of creating ProcessEngine in Activiti.

    We also saw different properties and approaches to handle database configuration.

    As always, the code for examples we saw can be found over on GitHub.

    Partner – AEGIK AB – NPI EA (tag = SQL)
    announcement - icon

    Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.

    The Jet Profiler was built for MySQL only, so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.

    Critically, it has very minimal impact on your server's performance, with most of the profiling work done separately - so it needs no server changes, agents or separate services.

    Basically, you install the desktop application, connect to your MySQL server, hit the record button, and you'll have results within minutes:

    out the Profiler

    Course – LS (cat=Java)

    Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

    >> CHECK OUT THE COURSE
    res – REST with Spring (eBook) (everywhere)