官术网_书友最值得收藏!

Suspending and resuming an instance via the CLI

In this recipe, we will learn how to suspend an instance without killing active requests. Once the running requests are completed, the next ones will not be accepted. This is a new feature available in WildFly 9.

Getting ready

To test this recipe, we will need the application named grace that you can find in my GitHub repository. If you skipped the Managing applications using the deployments folder recipe, please refer to it to download all the source code and the projects that you will need.

Start up your WildFly so we can directly connect to it via the CLI, as follows:

$ cd ~/WFC/wildfly
$ ./bin/standalone.sh

How to do it…

  1. First of all, deploy the application grace.war. Once the application has been deployed, open it using a browser at the following URL http://127.0.0.1:8080/grace

    This will hit the index.jsp page which increments a counter and then sleeps for 10 seconds, just to simulate a long running request.

  2. While running, open a terminal window and connect to the CLI as usual. Once there, do as follows:
    $ ./bin/jboss-cli.sh --connect
    [standalone@localhost:9990 /] :suspend
  3. Now, going back on the browser, your request should be done and you should see a page similar to the following one:
  4. On the other hand, to resume the instance, just invoke the following command:
    [standalone@localhost:9990 /] :resume

How it works…

The command itself is pretty easy. What you should know is what happens to the next user's requests. The next user would get the following page:

Obviously, you could handle the HTTP 503 code using a special page to warn the users about the technical problems due to the system's upgrade.

On the WildFly logs you should catch the following entry:

16:38:05,374 INFO  [org.jboss.as.server] (management-handler-thread - 7) WFLYSRV0211: Suspending server

The resume command is pretty easy as well. What needs to be noticed is that the user will not lose his current and active session, which is a really great feature from the user's point of view.

On the WildFly logs, you should catch the following entry:

16:38:25,347 INFO  [org.jboss.as.server] (management-handler-thread - 8) WFLYSRV0212: Resuming server

Now if you go back to the application and refresh the page, you should see the counter increasing from where it stopped, as depicted in the following image:

主站蜘蛛池模板: 丘北县| 墨玉县| 中超| 抚顺县| 吉水县| 长治市| 宜丰县| 山丹县| 日喀则市| 梧州市| 镇赉县| 武定县| 遂川县| 蓬溪县| 远安县| 大石桥市| 水富县| 来安县| 甘德县| 平顺县| 峨边| 尚义县| 襄垣县| 孝义市| 奈曼旗| 上栗县| 石城县| 阿拉尔市| 大庆市| 历史| 舒兰市| 巴楚县| 陆川县| 邵武市| 尚义县| 年辖:市辖区| 麦盖提县| 西乌| 石屏县| 慈利县| 库尔勒市|