Newer
Older
sink / src / main / java / org / flume / alarm / util / ThreadUtil.java
zhout on 2 Mar 2022 1 KB first commit
package org.flume.alarm.util;

import org.flume.alarm.restful.HttpClientUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by phantomli on 2016/2/17.
 */
public class ThreadUtil {
    public static void excuteMsg(Long id, String msg) throws UnsupportedEncodingException {
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        final Long jobId = id;
        final String alarmMsg = URLEncoder.encode(msg, "UTF-8");
        cachedThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    String retMsg = HttpClientUtils.post(Configure.getProperty("sendURL", "") + "?id=" + jobId
                            + "&msg="+alarmMsg , "");
                    Thread.sleep(500);
                    System.out.println("--------工单和告警推送至web后台成功 " + retMsg + ",工单id:" + jobId);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("--------工单和告警推送至web后台失败,工单id:" + jobId);
                }
            }
        });
    }
}