欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Windows如何設(shè)置定時重啟Tomcat

 更新時間:2024年01月02日 15:16:06   作者:謝小濤  
本文主要介紹了Windows如何設(shè)置定時重啟Tomcat,可以使用Windows系統(tǒng)的計劃任務(wù)程序,在這里設(shè)置定時執(zhí)行的.bat批處理文件,具有一定的參考價值,感興趣的可以了解一下

項目場景:

系統(tǒng):Windows 7

Tomcat:apache-tomcat-8.0.5

JDK:1.8

問題描述

最近項目的Tomcat隔一段時間就假死,最后想到的解決方式就是:每天凌晨1點重啟tomact。

解決方案:

使用Windows系統(tǒng)的計劃任務(wù)程序,可以在這里設(shè)置定時執(zhí)行的.bat批處理文件(將你要定時執(zhí)行的cmd命令放在這里),這樣就可以實現(xiàn)讓電腦在某個時刻做你想讓它干的事。

實現(xiàn)步驟:

一、創(chuàng)建tomcat重啟的腳本

        創(chuàng)建txt文件restart.txt,編輯內(nèi)容,把下面的內(nèi)容復(fù)制進(jìn)去,然后把綴改為.bat,最后文件名為:restart.bat  

echo 正在關(guān)閉Tomcat服務(wù),請稍等......

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Stop script for the CATALINA Server
rem ---------------------------------------------------------------------------

setlocal

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" stop %CMD_LINE_ARGS%

:end


echo 關(guān)閉Tomcat服務(wù)完成

ping 127.0.0.1 -n 20
echo ******************************************

echo 正在啟動Tomcat服務(wù),請稍等......

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem ---------------------------------------------------------------------------

setlocal

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end


echo 啟動Tomcat服務(wù)完成

把restart.bat 文件復(fù)制到apache-tomcat-8.0.50\bin目錄下 ,然后可以直接雙擊運行,啟動會報個錯,是因為tomcat沒啟動,是正常的。

 二、創(chuàng)建任務(wù)計劃程序

1、開始菜單搜索“任務(wù)計劃程序”

或者到控制面板里面找到“計劃任務(wù)”

2、彈出任務(wù)計劃程序界面,在右側(cè)點擊創(chuàng)建任務(wù)

3、輸入 名稱和描述

4、點擊觸發(fā)器選項卡,點擊左下角新建,彈出新建操作,新建一個觸發(fā)器,每天凌晨一點觸發(fā)

5、點擊操作選項卡,點擊左下角新建,彈出新建操作,點擊瀏覽。選擇要執(zhí)行的腳本restart.bat ,點擊打開確定。

附加: 

這里說下nginx配置集群和tomcat實現(xiàn)session共享

首先要啟動兩個tomcat,然后端口不一樣,比如8889和8899

1、nginx.conf關(guān)鍵配置

upstream serverlist {
   #最少連接數(shù),根據(jù)連接數(shù)多少自動選擇后端服務(wù)器,連接數(shù)相等時根據(jù)權(quán)重選擇
   least_conn;
   #每個請求按訪問ip的hash結(jié)果分配,這樣每個訪客固定訪問一個后端服務(wù)器,可以解決session的問題
   #ip_hash; 
   #若120秒內(nèi)出現(xiàn)2次錯誤,則下個120秒內(nèi)不再訪問此服務(wù)器,weight權(quán)重越大,請求機(jī)會越多
   server 127.0.0.1:8889 max_fails=2 fail_timeout=120s weight=1;#主服務(wù)
   server 127.0.0.1:8899 max_fails=2 fail_timeout=120s weight=1 backup;#備用tomcat服務(wù),主服務(wù)掛了會調(diào)用備用服務(wù)
}

2、tomcat實現(xiàn)session共享 

server.xml在Engine標(biāo)簽內(nèi)加上配置

<Engine name="Catalina" defaultHost="localhost">
    <!-- tomcat集群session共享 -->
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
</Engine>

修改web項目,工程WEB-INF下的web.xml,添加如下一句配置 

<distributable />

到此這篇關(guān)于Windows如何設(shè)置定時重啟Tomcat 的文章就介紹到這了,更多相關(guān)Tomcat定時重啟內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Tomcat 配置與優(yōu)化方案詳解

    Tomcat 配置與優(yōu)化方案詳解

    這篇文章主要介紹了Tomcat 配置與優(yōu)化方案詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-06-06
  • Java開啟/關(guān)閉tomcat服務(wù)器的方法

    Java開啟/關(guān)閉tomcat服務(wù)器的方法

    這篇文章主要介紹了Java開啟/關(guān)閉tomcat服務(wù)器的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-06-06
  • Tomcat環(huán)境變量如何配置

    Tomcat環(huán)境變量如何配置

    這篇文章主要以文字?jǐn)⑹龅男问綖榇蠹以敿?xì)介紹了Tomcat環(huán)境變量如何配置,以及驗證方法,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Centos7.3下Tomcat8的安裝配置教程

    Centos7.3下Tomcat8的安裝配置教程

    這篇文章主要為大家詳細(xì)介紹了Centos7.3下Tomcat8的安裝和配置,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • 使用JMX監(jiān)控Tomcat示例代碼

    使用JMX監(jiān)控Tomcat示例代碼

    這篇文章主要介紹了使用JMX監(jiān)控Tomcat示例代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • IntelliJ?IDEA中配置Tomcat超詳細(xì)教程

    IntelliJ?IDEA中配置Tomcat超詳細(xì)教程

    這篇文章主要介紹了IntelliJ?IDEA中配置Tomcat超詳細(xì)教程,需要的朋友可以參考下
    2022-08-08
  • Tomcat服務(wù)器圖片地址中文路徑問題解決辦法

    Tomcat服務(wù)器圖片地址中文路徑問題解決辦法

    這篇文章主要介紹了Tomcat服務(wù)器圖片地址中文路徑問題解決辦法,Tomcat中如果設(shè)置不當(dāng),中文路徑會導(dǎo)致找不到文件錯誤,本文就講解了解決這個問題的方法,需要的朋友可以參考下
    2015-05-05
  • tomcat 6.0.20在一個機(jī)器上安裝多個服務(wù)的方法

    tomcat 6.0.20在一個機(jī)器上安裝多個服務(wù)的方法

    當(dāng)前前提是你已經(jīng)可以同時運行他們了,他們的端口不能相同,這里只是解釋如何把它們做成服務(wù)
    2009-08-08
  • 搭建Tomcat 8源碼開發(fā)環(huán)境的步驟詳解

    搭建Tomcat 8源碼開發(fā)環(huán)境的步驟詳解

    相信大家都知道開源軟件tomcat目前幾乎已經(jīng)是Java web開發(fā)的必備軟件了,目前有很多關(guān)于tomcat的書籍,已經(jīng)通過配置對tomcat進(jìn)行一些跟應(yīng)用業(yè)務(wù)功能的調(diào)優(yōu),但感覺如果僅僅只是了解一些配置,可能稍微少了點什么,下面通過本文深入到源代碼中進(jìn)行學(xué)些和了解。
    2016-10-10
  • Tomcat啟動war包卡死及啟動慢的問題解決

    Tomcat啟動war包卡死及啟動慢的問題解決

    本文主要介紹了Tomcat啟動war包卡死及啟動慢的問題解決,文中通過圖文示例介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-08-08

最新評論