introduction of JDBC Connection Pooling

jdbc-connection-pooling

This article will tell you about how web developers can provide a strategy for applications that must handle connection pooling. This document will give an overview of JDBC connection pooling as specified by the JDBC 3.0 specification. This Connection Pool Manager is shipped with DataDirect Connect® for JDBC and DataDirect SequeLink® for JDBC. Finally, this document provides an example showing performance benchmarks that demonstrate the performance benefit by using connection pooling.

Connection Pooling

On the other side, establishing JDBC connections can be resource-expensive. Especially, when the JDBC API is used in a middle-tier server environment, or when DataDirect Connect for JDBC or DataDirect SequeLink for JDBC is running on a Java-enabled web server. In this condition, when connection pooling is used performance can be improved significantly. Rather than created connections each time a connection is requested, connection will be reused in Connection pooling. A connection pool works by a connection pooling module as a layer on top of any standard JDBC driver product.

Connection pooling will not affect how an application is coded as it will be performed in the background. However, the application must use a DataSource object (an object implementing the DataSource interface) in order to obtain a connection instead of using the DriverManager class. A class implementing the DataSource interface may or may not provide connection pooling. A DataSource object registers with a JNDI naming service. After a DataSource object is registered the application will retrieve it in the standard way from the JNDI naming service.

For example:

Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(“jdbc/SequeLink”);

The lookup returns a connection from the pool if one is available, if the DataSource object provides connection pooling. However, if there is no connection pooling or if there are no available connections in the pool, the lookup creates a new connection. The application will get advantages from connection reuse without the need to change any code. In fact, reused connections from the pool act the same way as newly created physical connections. Connection to the database and data access works in the usual way with the application. Furthermore, the application explicitly closes the connection, when the application has finished its work with the connection.

For example:

Connection con = ds.getConnection(“scott”, “tiger”);
// Do some database activities using the connection…
con.close();

For future reuse, the pooling module will get signal from the closing event on a pooled connection signals to place the connection back in the connection pool.

3 JavaScript Libraries to Look Up for in 2017

3-javascript-libraries-to-look-up-for-in-2017

For some web developers, JavaScript’s ecosystem can be fatigue. Especially this year where there is a lot of tooling and configuring is required. So, to make your work easier, we submit a list of 3 generic libraries/frameworks for front-end development.

Vue.js

If you haven’t put any attention on Vue.js before, now you have to keep your eyes on. It is a tiny JavaScript framework which seems to primarily focus on views and give you only a handful of tools to regulate data for those views. Moreover, Vue.js is also good for a change as it doesn’t get stuffed with programming design pattern and limitations.

There are two types of Vue.js. A stand-alone version that includes the template compiler and the runtime version that doesn’t. You can see its simplicity, through an example of a component that shows a message and brings interactivity to a button to reverse the message.

<div id="app">
  <p>{{ message }}</p>
  <button v-on:click="reverseMessage">Reverse Message</button>
</div>
import Vue from 'vue'

new Vue({
  el: '#app',
  data: {
    message: 'Hello World!',
  },
  methods: {
    reverseMessage: function () {
      const reversedMessage = this.message
        .split('')
        .reverse()
        .join('');

      this.message = reversedMessage;
    },
  },
});

Don’t you worry about the existence of other plugins, as you still can find them on Vue.js. In fact, several guides are available to use there. This framework will be suitable for you, especially if you wish to have productive fast. It also scales well as the project grows.

Svelte

Svelte must be the latest JavaScript Libraries as it has been released in mid-November 2016. At some point, it may looks similar to Vue.js, but leaves a smaller footprint. “Traditional” frameworks need runtime code to define and execute modules; keeps state, update the views and do whatever frameworks do. Moreover, with Svelte you can dissolve into clean JavaScript code as of you didn’t use a framework at all. The big advantages that you can get is that its file size.

Svelte has plugins so you can compile the source code using Webpack, Browserify, Rollup or Gulp.

You can use the below example of creating the Vue.js example with Svelte as a comparison:

<p>{{ message }}</p>
<button on:click="reverseMessage()">Reverse Message</button>

<script>
export default {
  data () {
    return {
      message: 'Hello World!',
    }
  },
  methods: {
    reverseMessage () {
      const reversedMessage = this.get('message')
          .split('')
          .reverse()
          .join('');

      this.set({
        message: reversedMessage,
      });
    }
  }
};
</script>

The very same module created with Vue.js produces a 7kb bundle. Svelte produces a 2kb file.

In terms of performance, Svelte competes with Inferno. This makes Svelte becomes a good choice if you care about your application’s footprint. At the time of writing, Svelte either doesn’t have its plugin system documented, or doesn’t have one at all. The TODO indicates that Svelte will support plugins and might have an API to hook into the framework.

The compatibility of the compiled code depends on your build workflow stack, so it’s hard to say what its default compatibility is. Technically you should be able to achieve pre-ES% support by including ES5 shims.

To conditionally load and invoke modules, Conditioner.js is one of the good choices. The difference from other module loaders is that conditioner.js allows you define conditions under which to load and/or show a module. This results in reducing loading time and saving bandwidth.

However, you better already have functional components in place that are enhanced with a given JavaScript module. How those modules are defined is entirely up to you. You could even make it load modules from your favorite framework.

To get started, you can install it via npm: npm install conditioner-js.

The demo is unlike previous ones to better illustrate Conditioner.js’ features. Imagine we wish to show the time remaining to an event. A module is shown like this:

import moment from 'moment';

export default class RelativeTime {
  /**
   * Enhance given element to show relative time.
   * @param {HTMLElement} element - The element to enhance.
   */
  constructor(element) {
    this.startTime = moment(element.datetime);

    // Update every second
    setInterval(() => this.update(), 1000);
    this.update();
  }

  /**
   * Update displayed relative time.
   */
  update() {
    element.innerHTML = this.startDate.toNow();
  }
}

It is so simple to initialize the module:

<time datetime="2017-01-01" data-module="ui/RelativeTime">2017</time>

Conditioner will then load the ui/RelativeTime module at this location in the DOM. Note the content is already present and in an acceptable format and the module only enhances that.

If you want a module to initialize only when it’s visible to a user, you can do so with conditions:

<!-- Show RelativeTime only if it is visible to the user -->
<time datetime="2017-01-01" data-module="ui/RelativeTime" data-conditions="element:{visible}">2017</time>
<!-- Keep showing RelativeTime after it was visible to the user -->
<time datetime="2017-01-01" data-module="ui/RelativeTime" data-conditions="element:{was visible}">2017</time>

Conditioner.js has quite an extensive list of monitors, which you use to define conditions. Don’t fret! You only have to include those you need, preventing the inclusion of unnecessary code.

You can also pass along options as a JSON string or a slightly more readable JSON variant.

<!-- JSON variant -->
<div data-module="ui/RelativeTime" data-options='unit:"seconds"'>...</div>
<!-- Or good old JSON -->
<div data-module="ui/RelativeTime" data-options='{"unit":"seconds"}'>...</div>

How to Combine JavaScript & SEO with Isomorphic JS

how-to-combine-javascript-seo-with-isomorphic-js

Like it or not, JavaScript is one of the most used programming languages. So, as web developers or SEO analysts, you need to know how JavaScript-based websites can offer you more benefits, especially if you’re building a new, large application that requires great SEO compatibility.

Google VS. JavaScript

Since last year, Google focuses mostly on supporting user experience and performance. Google even states that they are improving at crawling and indexing JavaScript. But, the results are still unreliable. For example, the user experience also isn’t all that great because it takes some time to load all the JavaScript libraries and bootstrap the application. An alternative is to use pre-rendering services that run your JavaScript application.

The benefit of this approach is that, in theory, you can pretend that the problem doesn’t exist and build your application in JavaScript any way you want.

But, this method is quite complex and resulted in complex debugging to fix. This problem is quite hard to notice. In fact, many cases find aware about it after your rankings are affected.

Fortunately, you can resolve this problem with Isomorphic applications. Isomorphic applications solve the problem of crawling and indexing by performing an initial render on the server and then using that HTML as a base for bootstrapping the JavaScript application in the browser. With Isomorphic approach, you can get the best of two worlds, between HTML and JavaScript.

How Does It Work?

By this technique, you can have the same JavaScript code used by your application run on both the server and the client. Moreover, you can also feed your application with some data coming from the database on the server, run it, and capture the resulting HTML output that would normally require a browser to assemble. This output can then be served as your initial HTML to everyone who requests it (including crawlers, such as the Google Bot).

Benefits of Isomorphic Applications

  • Search Engine Indexability

Executing code on the server to render static pages and then leaving all the JS responsible for user interactions to be run by the browser.

  • Perceived Load Time is Faster

If you wish to reduce wasting your time in waiting for the app/website to bootstrap and perform initial AJAX requests, Isomorphic is the best choice for you. In fact, you will no longer need for the majority of AJAX calls and there is less rendering happening on the client side.

  • Great Technique

As it is stated before, isomorphic is great as it solves the SEO indexing problems, results in faster load times, and simplifies the application stack.  In addition, it gives more benefits for large code bases. But nothing comes for free.

  • You Must Use Certain Technologies

As it’s not a plug-and-play solution, you will need a significant amount of work to implement.

  • You Need Expertise

Isomorphic is not meant for developers who are afraid to experiment. Therefore, you should hire developers with great talent and love doing experiment.