본문 바로가기

JAVA

Timer

Timer time = new Timer();
int tick = 5000;    // 5 sec
time.scheduleAtFixedRate(this, new Date(), tick);
time.cancel();



//
// Copyright (c) 2010, cheol-dong choi, < http://www.sarangnamu.net>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

public class CTimeOverEraser {
    private Timer _timer = new Timer();
    private Vector _taskList = new Vector();

    /////////////////////////////////////////////////////////////

    CTimeOverEraser() {
        init();
    }

    public void init() {
        CLog.lev2("init timer!");

        // 여기서 path 가 여러개면 loop 돌리면 되는데
        // 일단 임시로.. 하나만..
        //
        _timer.scheduleAtFixedRate(
                new CEraserData(CXMLConfig.getInstance().getContent("TimeoverPath")),
                new Date(),
                Integer.parseInt(CXMLConfig.getInstance().getAttribute("Timeover", "Interval")));
    }

    // sub class
    class CEraserData extends TimerTask {
        public String _path;

        CEraserData(String path)
        {
            _path = path;
        }

        @Override
        public void run() {
            CLog.lev1("running timer! <delete file! '" + _path + "'>");
        }
    }
}





http://www.luciole.kr/117

'JAVA' 카테고리의 다른 글

jar  (0) 2013.09.26
maven  (0) 2013.09.26
string to int  (0) 2013.09.26
Map  (0) 2013.09.26
kxml2 sample code  (0) 2013.09.26