JAX-RS框架,使Tomcat啓動即可執行類的方法

目前我也不是很懂這個框架,但已試驗成功,故記錄之。

畢竟只是改代碼,不是在寫代碼。


1.在composite組件中配置

    <sca:component name="ManageFiles">
        <sca:implementation.java class="com.xx.xx.xx.ManageFiles"/>
    </sca:component>
別忘了佈局.composite_graphic

    <componentgraphic name="ManageFiles">
        <constraint>
            <height>103</height>
            <width>178</width>
            <x>755</x>
            <y>437</y>
            <location>
                <x>755</x>
                <y>437</y>
            </location>
            <size>
                <width>178</width>
                <height>103</height>
            </size>
        </constraint>
    </componentgraphic>
當然,要是我會直接拖動組件的話,就不用這麼麻煩了


2.在類前加上註解

@Composite
@EagerInit


3.定時執行任務

protected ScheduledExecutorService executor;


4.線程
Runnable r = new Runnable ()


測試代碼:

@Composite
@EagerInit
public class ManageFiles {

	@Resource
	protected ScheduledExecutorService executor;

	@Init
	public void call () {
		Runnable r = new Runnable () {
			@Override
			public void run() {
				try {
					System.out.println("啦啦啦啦啦啦啦");

				} catch (Throwable e) {
					e.printStackTrace();
				}
			}
		};
		//	每十秒執行一次
		executor.scheduleAtFixedRate(r, 0, 10, TimeUnit.SECONDS);
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章