不知道为啥会报:线程“main”java.lang中的异常。无法初始化类JdbcUtil.JDBCUtils的错误?
package Jdbc;

import JdbcUtil.JDBCUtils;
import domain.user;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class JdbcUtilDemo1 {
    public static void main(String[] args) {

            List<user> list = new JdbcUtilDemo1().findAll2();
            System.out.println(list);
            System.out.println(list.size());
        }

    /*
    演示JDBC工具类
     */
    public List<user> findAll2() {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        List<user> list = null;
        try {/*//1.注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取连接
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/eesy_mybatis?useSSL=false&serverTimezone=CTT","root","1799510625hgj");*/
            connection = JDBCUtils.getConnection();
            //3.定义sql
            String sql = "select * from user";
            //4.获取执行sql的对象
            statement = connection.createStatement();
            //5.执行sql
            resultSet = statement.executeQuery(sql);
            //6.遍历结果集,封装对象,装载集合
            user user = null;
            list = new ArrayList<user>();
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String username = resultSet.getString("username");
                Date birthday = resultSet.getDate("birthday");
                String sex = resultSet.getString("sex");
                String address = resultSet.getString("address");
                //创建user对象,并赋值
                user = new user();
                user.setId(id);
                user.setUsername(username);
                user.setBirthday(birthday);
                user.setSex(sex);
                user.setAddress(address);
                //装载集合
                list.add(user);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            //释放资源
       /* if(resultSet != null){
            resultSet.close();
        }
        if(statement != null){
            statement.close();
        }
        if(connection != null){
            connection.close();
        }*/
            JDBCUtils.close(resultSet, statement, connection);
        }
    return list;
    }
}

2个回答

异常信息是什么,看异常跟一下代码。这就是基础的 JDBC 连接逻辑,检查下 JDBC 的几项信息看看。

图片说明

你没感觉到你使用JDBCUtils.getConnection();和DriverManager.getConnection("jdbc:mysql://localhost:3306/eesy_mybatis?useSSL=false&serverTimezone=CTT","root","1799510625hgj");有什么区别吗

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Runnable 中抛出java.lang.ArrayIndexOutOfBoundsException: -1
[已解决] SimpleDateFormat.format并发调用会有问题private SimpleDateFormat.StringBuffer format(Date date, StringBuffer toAppendTo, FieldDelegate delegate) 里面用了calendar.setTime(date);这玩意是全局的,后面还会调用它,所以并发时候会出问题。 Random中protected Random.next(int bits);采用AtomicLong的CAS操作并发时候不会出问题。 ------------------------------------------------------------------------------ 每个Task有自己的ArrayList实例,在多线程情况下每个ArrayList实例应该不存在并发写入啊,为没什么还报ArrayIndexOutOfBoundsException: -1 求助大神,网上找了好久没结果。 ``` import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import static java.lang.System.out; public class TestArrayList { public static void main(String[] args){ TestArrayList t= new TestArrayList(); t.testInsertRows(); } private static int millisecondOf1Day= 1000*3600*24; private static int millisecondOf5Min= 1000*60*5; private static final SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final ExecutorService pool= Executors.newFixedThreadPool(8); public void testInsertRows(){ Random random= new Random(); int taskId= 0; for(int i=0; i< 8; i++){ taskId++; pool.submit(new Task(taskId, 10000, null)); } out.println("all submited!"); } static class Task implements Runnable{ private Integer id; private List<Bean> list; private int rowCount; private int count=0; private Random random; public Task(Integer id, Integer rowCount, Random random){ this.id= id; this.list= new ArrayList<>(rowCount+1); this.rowCount= rowCount; // this.random= random; this.random= new Random(); } @Override public void run() { out.println("task:"+id+" is running! "+Thread.currentThread()); try{ for(int j=0; j< rowCount; j++ ){ Long randomTime= random.nextLong(); Date validityDate= new Date(randomTime- millisecondOf1Day), startDate= new Date(randomTime), endDate= new Date(randomTime+ 2*millisecondOf1Day); Bean bean = new Bean(); bean.setField0("K0000033"); bean.setField1("0001"); bean.setField2(sdf.format(validityDate)); bean.setField3(new Double(0.0).toString()); bean.setField4(sdf.format(startDate)); bean.setField5(sdf.format(endDate)); list.add(bean); } out.println("list is prepared in thread:"+id); Thread.sleep(millisecondOf5Min);// out.println(count+" rows has been inserted in thread:"+id); }catch (Exception e) { synchronized (out) { out.println("task:"+id+" in error"+Thread.currentThread()); e.printStackTrace(); out.println("task:"+id+" error info print completed"); } } } } } class Bean{ private String field0; private String field1; private String field2; private String field3; private String field4; private String field5; private String field6; /** * @return the field0 */ public String getField0() { return field0; } /** * @param field0 the field0 to set */ public void setField0(String field0) { this.field0 = field0; } /** * @return the field1 */ public String getField1() { return field1; } /** * @param field1 the field1 to set */ public void setField1(String field1) { this.field1 = field1; } /** * @return the field2 */ public String getField2() { return field2; } /** * @param field2 the field2 to set */ public void setField2(String field2) { this.field2 = field2; } /** * @return the field3 */ public String getField3() { return field3; } /** * @param field3 the field3 to set */ public void setField3(String field3) { this.field3 = field3; } /** * @return the field4 */ public String getField4() { return field4; } /** * @param field4 the field4 to set */ public void setField4(String field4) { this.field4 = field4; } /** * @return the field5 */ public String getField5() { return field5; } /** * @param field5 the field5 to set */ public void setField5(String field5) { this.field5 = field5; } /** * @return the field6 */ public String getField6() { return field6; } /** * @param field6 the field6 to set */ public void setField6(String field6) { this.field6 = field6; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "Bean [field0=" + field0 + ", field1=" + field1 + ", field2=" + field2 + ", field3=" + field3 + ", field4=" + field4 + ", field5=" + field5 + ", field6=" + field6 + "]"; } } ``` task:1 is running! Thread[pool-1-thread-1,5,main] task:4 is running! Thread[pool-1-thread-4,5,main] task:3 is running! Thread[pool-1-thread-3,5,main] task:2 is running! Thread[pool-1-thread-2,5,main] task:5 is running! Thread[pool-1-thread-5,5,main] task:6 is running! Thread[pool-1-thread-6,5,main] all submited! task:7 is running! Thread[pool-1-thread-7,5,main] task:8 is running! Thread[pool-1-thread-8,5,main] task:7 in errorThread[pool-1-thread-7,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:64) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:7 error info print completed task:8 in errorThread[pool-1-thread-8,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:65) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:8 error info print completed task:4 in errorThread[pool-1-thread-4,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:62) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:4 error info print completed task:1 in errorThread[pool-1-thread-1,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:64) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:1 error info print completed task:5 in errorThread[pool-1-thread-5,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:65) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:5 error info print completed task:3 in errorThread[pool-1-thread-3,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:64) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:3 error info print completed task:6 in errorThread[pool-1-thread-6,5,main] java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Calendar.getDisplayName(Unknown Source) at java.text.SimpleDateFormat.subFormat(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.SimpleDateFormat.format(Unknown Source) at java.text.DateFormat.format(Unknown Source) at com.haimian.test.concurrent.TestArrayList$Task.run(TestArrayList.java:64) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) task:6 error info print completed list is prepared in thread:2
新人求助关于java.lang.StackOverflowError的异常问题
public class ProcessRow { Properties source= new Properties(); { try { FileInputStream fis = new FileInputStream(new File( inputPropertieName())); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); source.load(isr); fis.close(); } catch (Exception e) { // throw new ExceptionInInitializerError(e); } } public String filterAlphabet(String alph) { alph = alph.replaceAll("[^(A-Z)]", ""); return alph; } public String Pname() { UseProcess f=new UseProcess(); String hai = f.fileName; String a = filterAlphabet(hai); String b = hai.substring(hai.indexOf(a), hai.indexOf(a) + 6); return b; } public String inputPropertieName() { /* * System.out.println("请输入配置文件名称:"); Scanner a = new Scanner(System.in); * String propertieName = a.next(); */ // a.close(); ProcessRow a = new ProcessRow(); String propertieName = a.Pname(); return propertieName; } Exception in thread "main" java.lang.StackOverflowError at java.util.Dictionary.<init>(Dictionary.java:55) at java.util.Hashtable.<init>(Hashtable.java:251) at java.util.Hashtable.<init>(Hashtable.java:283) at java.util.Properties.<init>(Properties.java:143) at java.util.Properties.<init>(Properties.java:135) at test.ProcessRow.<init>(ProcessRow.java:18) at test.ProcessRow.inputPropertieName(ProcessRow.java:51) at test.ProcessRow.<init>(ProcessRow.java:22) at test.ProcessRow.inputPropertieName(ProcessRow.java:51) at test.ProcessRow.<init>(ProcessRow.java:22) at test.ProcessRow.inputPropertieName(ProcessRow.java:51)
MediaRecorder录屏,Socket传输录屏内容报错java.lang.IllegalStateException
用模拟器调试可以运行,用真机测试在 mediaRecorder.prepare();抛异常 ``` package www.xjw.com.mymiracast2.screenrecordservice; import android.app.Notification; import android.app.Service; import android.content.Context; import android.content.Intent; import android.hardware.display.DisplayManager; import android.hardware.display.VirtualDisplay; import android.media.MediaRecorder; import android.media.projection.MediaProjection; import android.media.projection.MediaProjectionManager; import android.os.IBinder; import android.os.ParcelFileDescriptor; import java.net.Socket; /** * Created by dzjin on 2018/1/9. */ public class ScreenRecordService extends Service { private int resultCode; private Intent resultData=null; private MediaProjection mediaProjection=null; private MediaRecorder mediaRecorder=null; private VirtualDisplay virtualDisplay=null; private int mScreenWidth; private int mScreenHeight; private int mScreenDensity; private static String filePathName; private Socket receiver = null; private ParcelFileDescriptor pfd = null; private Context context=null; private String host = null; private int port = 8989; @Override public void onCreate() { super.onCreate(); //startForeground(2, new Notification()); } /** * 每次客户端通过调用startService(Intent)显式启动服务时,系统调用startService(Intent), *提供它提供的参数和表示启动请求的唯一整数标记。 * 不要直接调用这个方法。 * @param intent * @param flags * @param startId * @return */ @Override public int onStartCommand(Intent intent, int flags, int startId) { try{ resultCode=intent.getIntExtra("resultCode",-1); resultData=intent.getParcelableExtra("resultData"); mScreenWidth=intent.getIntExtra("mScreenWidth",0); mScreenHeight=intent.getIntExtra("mScreenHeight",0); mScreenDensity=intent.getIntExtra("mScreenDensity",0); filePathName=intent.getStringExtra("filePathName"); host=intent.getStringExtra("host"); port=intent.getIntExtra("port",8989); receiver = new Socket(host, port); pfd = ParcelFileDescriptor .fromSocket(receiver); mediaProjection=createMediaProjection(); mediaRecorder=createMediaRecorder(); virtualDisplay=createVirtualDisplay(); mediaRecorder.start(); }catch (Exception e) { e.printStackTrace(); } /** * START_NOT_STICKY: *从onStartCommand返回的常量(Intent, int, int):如果这个服务的进程是 *在启动时被杀死(从onStartCommand(Intent, int, int)返回后), *没有新的start意图交付给它,然后将服务从 *启动状态,在以后显式调用Context.startService(Intent)之前不要重新创建。 *服务将不会接收带有空意图的onStartCommand(Intent, int, int)调用 *因为如果没有等待交付的意图,它将不会重新启动。 */ return Service.START_NOT_STICKY; } public MediaProjection createMediaProjection(){ /** *使用getSystemService(类)检索MediaProjectionManager实例 *管理媒体放映会议。 */ return ((MediaProjectionManager)getSystemService(Context.MEDIA_PROJECTION_SERVICE)) .getMediaProjection(resultCode,resultData); /** *检索从成功的屏幕捕获请求中获得的MediaProjection。 *如果startActivityForResult()的结果不是RESULT_OK,则*将为null。 */ } private MediaRecorder createMediaRecorder(){ //用于录制音频和视频。录音控制是基于一个简单的状态机。 MediaRecorder mediaRecorder=new MediaRecorder(); //设置要录音的源。 //mediaRecorder.setAudioSource(MediaRecorder. AudioSource.CAMCORDER); //设置要录制的视频源。 mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); //设置录制过程中产生的输出的格式。 //3GPP媒体文件格式 mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_2_TS); //设置录音格式 //mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //设置录像编码比特率。 //param:以比特/秒为单位的视频编码比特率 mediaRecorder.setVideoEncodingBitRate(5*mScreenWidth*mScreenHeight); //设置录像编码器用于录像。 mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); //设置要拍摄的视频的宽度和高度。 mediaRecorder.setVideoSize(mScreenWidth,mScreenHeight); //设置要捕获视频的帧速率。 mediaRecorder.setVideoFrameRate(60); try{ mediaRecorder.setOutputFile(pfd.getFileDescriptor()); //mediaRecorder.setOutputFile(filePathName); **此次抛异常** //准备记录器开始捕捉和编码数据。 mediaRecorder.prepare(); }catch (Exception e){ e.printStackTrace(); } return mediaRecorder; } private VirtualDisplay createVirtualDisplay(){ /** *名称字符串:虚拟显示的名称,必须是非空的。这个值不能为空。 width int:虚拟显示的宽度,以像素为单位。必须大于0。 高度int:虚拟显示器的高度,以像素为单位。必须大于0。 dpi int: dpi中虚拟显示的密度。必须大于0。 标志int:虚拟显示标志的组合。有关标志的完整列表,请参见DisplayManager。 surface surface:虚拟显示内容应该呈现到的表面,如果一开始没有,则为null。 回调virtualdisplay。回调:当虚拟显示的状态改变时调用的回调,如果没有,则为空。 处理程序处理程序:应该在其上调用回调的处理程序,如果应该在调用线程的主循环程序上调用回调,则为null。 */ /** * DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR *虚拟显示标志:当没有显示内容时,允许在私有显示上镜像内容。 */ return mediaProjection.createVirtualDisplay("mediaProjection",mScreenWidth,mScreenHeight,mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,mediaRecorder.getSurface(),null,null); } @Override public void onDestroy() { super.onDestroy(); if(virtualDisplay!=null){ virtualDisplay.release(); virtualDisplay=null; } if(mediaRecorder!=null){ mediaRecorder.stop(); mediaRecorder=null; } if(mediaProjection!=null){ mediaProjection.stop(); mediaProjection=null; } } @Override public IBinder onBind(Intent intent) { System.out.println("==============================="); return null; } } ``` I/MediaRecorder: enter in file frameworks/av/media/libmedia/mediarecorder.cpp, function prepare, line 461 I/IMediaRecorder: prepare (BpMediaRecorder client) in file frameworks/av/media/libmedia/IMediaRecorder.cpp, function prepare, line 249 W/com.mymiracast2: type=1400 audit(0.0:104572): avc: denied { read write } for path="socket:[8870267]" dev="sockfs" ino=8870267 scontext=u:r:mediaserver:s0 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=tcp_socket permissive=0 E/MediaRecorder: prepare failed: -38 W/zygote64: Got a deoptimization request on un-deoptimizable method void android.media.MediaRecorder._prepare() W/System.err: java.lang.IllegalStateException W/System.err: at android.media.MediaRecorder._prepare(Native Method) W/System.err: at android.media.MediaRecorder.prepare(MediaRecorder.java:1017) W/System.err: at www.xjw.com.mymiracast2.screenrecordservice.ScreenRecordService.createMediaRecorder(ScreenRecordService.java:137) W/System.err: at www.xjw.com.mymiracast2.screenrecordservice.ScreenRecordService.onStartCommand(ScreenRecordService.java:79) W/System.err: at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4151) W/System.err: at android.app.ActivityThread.-wrap21(Unknown Source:0) W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2119) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:108) W/System.err: at android.os.Looper.loop(Looper.java:166) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7529) W/System.err: at java.lang.reflect.Method.invoke(Native Method) W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) E/MediaRecorder: SurfaceMediaSource could not be initialized! W/System.err: java.lang.IllegalStateException: failed to get surface at android.media.MediaRecorder.getSurface(Native Method) W/System.err: at www.xjw.com.mymiracast2.screenrecordservice.ScreenRecordService.createVirtualDisplay(ScreenRecordService.java:160) at www.xjw.com.mymiracast2.screenrecordservice.ScreenRecordService.onStartCommand(ScreenRecordService.java:80) W/System.err: at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4151) at android.app.ActivityThread.-wrap21(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2119) at android.os.Handler.dispatchMessage(Handler.java:108) W/System.err: at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7529) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) D/StrictMode: StrictMode policy violation; ~duration=7334 ms: android.os.StrictMode$StrictModeNetworkViolation: policy=65543 violation=4 at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1466) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:201) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:183) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356) at java.net.Socket.connect(Socket.java:616) at java.net.Socket.connect(Socket.java:565) at java.net.Socket.<init>(Socket.java:445) at java.net.Socket.<init>(Socket.java:217) at www.xjw.com.mymiracast2.screenrecordservice.ScreenRecordService.onStartCommand(ScreenRecordService.java:74) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4151) at android.app.ActivityThread.-wrap21(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2119) at android.os.Handler.dispatchMessage(Handler.java:108) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7529) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) D/StrictMode: StrictMode policy violation; ~duration=7332 ms: android.os.StrictMode$StrictModeNetworkViolation: policy=65543 violation=4 ``` ```
使用dbcp连接数据库报错java.lang.NumberFormatException: For input string: "20 "?
内容: 换了一个工程就可以跑得动 报错: ``` java.lang.NumberFormatException: For input string: "20 " at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:228) at com.ekihin.part01.day20.DBCPDemo.<clinit>(DBCPDemo.java:21) at com.ekihin.part01.day20.DBCPDemoTest.main(DBCPDemoTest.java:15) Exception in thread "main" java.lang.NullPointerException at com.ekihin.part01.day20.DBCPDemo.getConnection(DBCPDemo.java:29) at com.ekihin.part01.day20.DBCPDemoTest.main(DBCPDemoTest.java:15) ``` 类: ``` import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class DBCPDemoTest { public static void main(String[] args) throws Exception { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "Update emp set ename = ? where ename = ? "; conn = DBCPDemo.getConnection(); ps = conn.prepareStatement(sql); ps.setObject(1, "彭奕滨"); ps.setObject(2, "ekihin"); int rows = 0; rows = ps.executeUpdate(); System.out.println(rows); DBCPDemo.closeAll(conn, ps, rs); } } ``` ``` import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSourceFactory; public class DBCPDemo { private static DataSource ds = null; static { Properties pt = new Properties(); try { pt.load(DBCPDemo.class.getClassLoader().getResourceAsStream("dbcpconfig.properties")); ds = BasicDataSourceFactory.createDataSource(pt); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static Connection getConnection() throws SQLException{ //返回一个连接对象,不要用DriverManager获取,而是连接池中获取 return ds.getConnection(); } //关闭所有资源的统一代码 public static void closeAll(Connection conn,Statement st,ResultSet rs){ //负责关闭 if(conn != null){ try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(st != null){ try { st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(rs != null){ try { rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } ```
Android如何在自定义view中发送消息给主线程
求求各位大神支招,小弟在自己开发一个东西,遇到了一个小问题。 ![![图片说明](https://img-ask.csdn.net/upload/201603/15/1458054699_661302.jpg) 图片说明](https://img-ask.csdn.net/upload/201603/15/1458054689_616589.jpg) 我在自定义view的onDraw里,当条件达到后就开启一个子线程发送消息给主线程,让主线程中的handler接收消息并执行相应的动作,可是在Log的输出下只能输出“子线程,”而没有”handlemessage“,并且异常退出,退出代码如下: 03-15 22:50:34.593: W/dalvikvm(27492): threadid=1: thread exiting with uncaught exception (group=0x41c6ece0) 03-15 22:50:34.593: W/dalvikvm(27492): threadid=1: uncaught exception occurred 03-15 22:50:34.593: W/System.err(27492): java.lang.NullPointerException 03-15 22:50:34.593: W/System.err(27492): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:4094) 03-15 22:50:34.593: W/System.err(27492): at android.os.Handler.dispatchMessage(Handler.java:110) 03-15 22:50:34.593: W/System.err(27492): at android.os.Looper.loop(Looper.java:193) 03-15 22:50:34.593: W/System.err(27492): at android.app.ActivityThread.main(ActivityThread.java:5348) 03-15 22:50:34.593: W/System.err(27492): at java.lang.reflect.Method.invokeNative(Native Method) 03-15 22:50:34.593: W/System.err(27492): at java.lang.reflect.Method.invoke(Method.java:515) 03-15 22:50:34.593: W/System.err(27492): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 03-15 22:50:34.594: W/System.err(27492): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 03-15 22:50:34.594: W/System.err(27492): at dalvik.system.NativeStart.main(Native Method) 03-15 22:50:34.594: W/dalvikvm(27492): threadid=1: calling UncaughtExceptionHandler 03-15 22:50:34.594: I/dalvikvm(27492): +++ calling Ljava/lang/ThreadGroup;.uncaughtException 03-15 22:50:34.594: D/dalvikvm(27492): threadid=11: bye! 03-15 22:50:34.595: E/AndroidRuntime(27492): FATAL EXCEPTION: main 03-15 22:50:34.595: E/AndroidRuntime(27492): Process: com.example.wyccustomview3, PID: 27492 03-15 22:50:34.595: E/AndroidRuntime(27492): java.lang.NullPointerException 03-15 22:50:34.595: E/AndroidRuntime(27492): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:4094) 03-15 22:50:34.595: E/AndroidRuntime(27492): at android.os.Handler.dispatchMessage(Handler.java:110) 03-15 22:50:34.595: E/AndroidRuntime(27492): at android.os.Looper.loop(Looper.java:193) 03-15 22:50:34.595: E/AndroidRuntime(27492): at android.app.ActivityThread.main(ActivityThread.java:5348) 03-15 22:50:34.595: E/AndroidRuntime(27492): at java.lang.reflect.Method.invokeNative(Native Method) 03-15 22:50:34.595: E/AndroidRuntime(27492): at java.lang.reflect.Method.invoke(Method.java:515) 03-15 22:50:34.595: E/AndroidRuntime(27492): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 03-15 22:50:34.595: E/AndroidRuntime(27492): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 03-15 22:50:34.595: E/AndroidRuntime(27492): at dalvik.system.NativeStart.main(Native Method)
flink-1.8.1测试运行自带的example/batch/WordCount出现以下问题
org.apache.flink.client.program.ProgramInvocationException:无法检索执行结果。(JobID:5a7165e1260c6316fa11d2760bd3d49f) 在org.apache.flink.client.program。rest .RestClusterClient.submitJob(RestClusterClient.java:260) 在org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:486) 在org.apache.flink.streaming.api.environment.StreamContextEnvironment.execute(StreamContextEnvironment.java:66) 在org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1511) at com.dataartisans.streamledger.examples.simpletrade.SimpleTradeExample.main(SimpleTradeExample.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497) 在org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529) 在org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421) 在org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:426) 在org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:804) 在org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:280) 在org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:215) 在org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1044) 在org.apache.flink.client.cli.CliFrontend.lambda $ main $ 16(CliFrontend.java:1120) at java.security.AccessController.doPrivileged(Native Method) 在javax.security.auth.Subject.doAs(Subject.java:422) 在org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1556) 在org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41) 在org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1120) 引起:org.apache.flink.runtime.client.JobSubmissionException:无法提交JobGraph。 在org.apache.flink.client.program。rest .RestClusterClient.lambda $ submitJob $ 25(RestClusterClient.java:379) at java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:870) at java.util.concurrent.CompletableFuture $ UniExceptionally.tryFire(CompletableFuture.java:852) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977) 在org.apache.flink.runtime.concurrent.FutureUtils.lambda $ retryOperationWithDelay $ 32(FutureUtils.java:213) at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760) at java.util.concurrent.CompletableFuture $ UniWhenComplete.tryFire(CompletableFuture.java:736) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:561) at java.util.concurrent.CompletableFuture $ UniCompose.tryFire(CompletableFuture.java:929) at java.util.concurrent.CompletableFuture $ Completion.run(CompletableFuture.java:442) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang。线程 .run(线程 .java:745) 引起:java.util.concurrent.CompletionException:org.apache.flink.runtime.concurrent.FutureUtils $ RetryException:无法完成操作。异常不可重试。 at java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:326) at java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:338) at java.util.concurrent.CompletableFuture.uniRelay(CompletableFuture.java:911) at java.util.concurrent.CompletableFuture $ UniRelay.tryFire(CompletableFuture.java:899) ......还有12个 引起:org.apache.flink.runtime.concurrent.FutureUtils $ RetryException:无法完成操作。异常不可重试。 ......还有10个 引起:java.util.concurrent.CompletionException:org.apache.flink.runtime。rest .util.RestClientException:[作业提交失败。] at java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:326) at java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:338) at java.util.concurrent.CompletableFuture.uniRelay(CompletableFuture.java:911) at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:953) at java.util.concurrent.CompletableFuture $ UniCompose.tryFire(CompletableFuture.java:926) ......还有4个 引起:org.apache.flink.runtime。rest .util.RestClientException:[作业提交失败。] 在org.apache.flink.runtime。rest .RestClient.parseResponse(RestClient.java:310) 在org.apache.flink.runtime。rest .RestClient.lambda $ submitRequest $ 364(RestClient.java:294) at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:952) ......还有5个 附件
lang异常的线程,这个怎么解决?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11 at com.homework.one.Display.<init>(Display.java:86) at com.homework.one.Menu.<init>(Menu.java:34) at com.homework.one.Menu.main(Menu.java:56) [CSDN移动问答][1] [1]: http://zhidao.baidu.com/question/361406740612267652.html
android 运行报错。 各位大神帮忙看看
在 problems 里面 没有提示错误,但是 运行起来就 一打开程序 就直接退出了。。看着貌似线程的问题。。 具体看不懂 请教各位大神。。 01-11 10:57:25.741: E/AndroidRuntime(25259): FATAL EXCEPTION: main 01-11 10:57:25.741: E/AndroidRuntime(25259): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marenbo.baidumap/com.marenbo.baidumap.MainActivity}: java.lang.NullPointerException 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.ActivityThread.access$600(ActivityThread.java:138) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.os.Handler.dispatchMessage(Handler.java:99) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.os.Looper.loop(Looper.java:213) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.ActivityThread.main(ActivityThread.java:4787) 01-11 10:57:25.741: E/AndroidRuntime(25259): at java.lang.reflect.Method.invokeNative(Native Method) 01-11 10:57:25.741: E/AndroidRuntime(25259): at java.lang.reflect.Method.invoke(Method.java:511) 01-11 10:57:25.741: E/AndroidRuntime(25259): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 01-11 10:57:25.741: E/AndroidRuntime(25259): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 01-11 10:57:25.741: E/AndroidRuntime(25259): at dalvik.system.NativeStart.main(Native Method) 01-11 10:57:25.741: E/AndroidRuntime(25259): Caused by: java.lang.NullPointerException 01-11 10:57:25.741: E/AndroidRuntime(25259): at com.marenbo.baidumap.MyOrientationListener.Start(MyOrientationListener.java:25) 01-11 10:57:25.741: E/AndroidRuntime(25259): at com.marenbo.baidumap.MainActivity.onStart(MainActivity.java:137) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.Activity.performStart(Activity.java:5018) 01-11 10:57:25.741: E/AndroidRuntime(25259): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044) 01-11 10:57:25.741: E/AndroidRuntime(25259): ... 11 more
定时任务quartz开启线程,在tomcat关闭时候,报内存泄露,如何解决?
报错内容如下 [INFO][2018-08-24 21:30:11] com.alibaba.druid.pool.DruidDataSource.close(DruidDataSource.java:1825) {dataSource-1} closed 24-Aug-2018 21:30:11.702 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [pool-2-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:745) 24-Aug-2018 21:30:11.702 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [pool-3-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:745) 24-Aug-2018 21:30:11.703 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [pool-4-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:745) 24-Aug-2018 21:30:11.705 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-apr-8080"] 24-Aug-2018 21:30:11.773 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-apr-8009"] 24-Aug-2018 21:30:11.825 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-apr-8080"] 24-Aug-2018 21:30:11.826 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-apr-8009"] ``` ``` 根据网上的解决方法,我已经关闭了定时任务Scheduler,关闭了开启定时任务的线程池,也关闭了数据源。为什么还是报错? 我的代码 package com.yz.robot.spring; import com.yz.robot.mcore.utils.SpringContextUtils; import com.yz.robot.mquartz.service.ScheduleJobService; import com.yz.robot.mquartz.service.impl.ScheduleJobServiceImpl; import com.yz.robot.mquartz.utils.ScheduleJob; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.impl.StdSchedulerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.sql.Driver; import java.sql.DriverManager; import java.util.Enumeration; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutorService; public class QuartzJobListener implements ServletContextListener { @Autowired private ScheduleJob scheduleJob; @Override public void contextInitialized(ServletContextEvent sce) { System.out.println("--------------开始-------"); } @Override public void contextDestroyed(ServletContextEvent sce){ WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); if (webApplicationContext != null){ Object scheduleJobServiceImpl = webApplicationContext.getBean("scheduleJob"); System.out.println("-------------------------2"); System.out.println(scheduleJobServiceImpl !=null); }else { System.out.println("获取应用程序上下文失败!"); } try { Scheduler defaultScheduler = StdSchedulerFactory.getDefaultScheduler(); System.out.println("-------------------------2"); System.out.println(defaultScheduler.isShutdown()); defaultScheduler.shutdown(true); Thread.sleep(1000); System.out.println(defaultScheduler.isShutdown()); ScheduleJob scheduleJob = (ScheduleJob) SpringContextUtils.getBean("scheduleJob"); //scheduleJobServiceImpl ExecutorService service = scheduleJob.getService(); System.out.println("-------------------------3"); System.out.println(service!=null); System.out.println(service.isShutdown()); List<Runnable> runnables = service.shutdownNow(); System.out.println(service.isShutdown()); Thread.sleep(1000); System.out.println("-------------------------4"); Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()){ Driver driver = drivers.nextElement(); DriverManager.deregisterDriver(driver); System.out.println("又注销了一个driver"+driver.toString()); } } catch (Exception e) { e.printStackTrace(); } } } 大佬们帮帮我吧??? ```
java编程,出现线程“main”中出现异常的问题
用idea编写java,出现这种情况 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at yecheng.Search.main(Search.java:18) Process finished with exit code 1 源代码: public class Search { public static void main(String[] arg){ MysqlDB db = new MysqlDB(); Index index = new Index(); ReadFile rf = new ReadFile(); File file = new File(arg[0]); try { rf.readFile(file); index.loadDB(db); int id = index.search(rf.fingerprint,15); System.out.println(id); } catch (Exception e) { e.printStackTrace(); System.out.println(e.toString()); } } }
关于java多线程操作invokeAll空指针的问题
求救各位大神: ``` public static void threadTestAll(String dirName) { long start = System.currentTimeMillis(); ExecutorService pool = Executors.newFixedThreadPool(30); List<Callable<String>> tasks = new ArrayList<Callable<String>>(); File dir = new File(dirName); for(File f:dir.listFiles(new myFilter())){ myTask t = new ThreadTest2().new myTask(f.getAbsolutePath()); tasks.add(t); } try { List<Future<String>> r = pool.invokeAll(tasks); for (Future<String> f : r) { if(f != null){ System.out.println(f); System.out.println("task result=" + f.get()); } } pool.shutdown(); long end = System.currentTimeMillis(); System.out.println("测试用了"+(end-start)+"毫秒"); } catch (Exception e) { System.out.println("here"); e.printStackTrace(); } } ``` ``` class myTask implements Callable<String> { final String fileName; public myTask(String fileName) { this.fileName = fileName; } @Override public String call() throws Exception { System.out.println("线程开始查找"+fileName); List<String> l = FileUtils.serachFileNames(fileName, "[七七电视www.77ds.com]蚁人TS清晰中字.mp4", false); if(l.size() != 0){ // System.out.println(l.get(0)); System.out.println(l.get(0)); return l.get(0); } return ""; // throw new Exception("没找到"); } } ``` 我的两段代码,没有发现任何有空指针异常的情况,单步调试也不知道哪出问题了,在这里 System.out.println(f); System.out.println("task result=" + f.get()); 打印也可以把对象打印出来,但不知道为啥,总有一个对象get的时候出错了,报空指针问题,求大神指教 这是结果 ``` 线程开始查找d:\$RECYCLE.BIN 线程开始查找d:\7450 线程开始查找d:\android 线程开始查找d:\360WiFi 线程开始查找d:\cha 线程开始查找d:\360Downloads 线程开始查找d:\maven 线程开始查找d:\opt 线程开始查找d:\Program Files (x86) 线程开始查找d:\DOWNLOAD 线程开始查找d:\RJ 线程开始查找d:\updateEdb 线程开始查找d:\work 线程开始查找d:\program 线程开始查找d:\kinggsoft 线程开始查找d:\Program Files 线程开始查找d:\迅雷下载 线程开始查找d:\shuju 线程开始查找d:\Youku Files 线程开始查找d:\System Volume Information 线程开始查找d:\备份 d:\迅雷下载\新建文件夹\[七七电视www.77ds.com]蚁人TS清晰中字.mp4 java.util.concurrent.FutureTask@6ef0eed6 task result= java.util.concurrent.FutureTask@bd05c81 task result= java.util.concurrent.FutureTask@1c691f36 task result= java.util.concurrent.FutureTask@398020cc task result= java.util.concurrent.FutureTask@ae94e92 task result= java.util.concurrent.FutureTask@5b2558d6 task result= java.util.concurrent.FutureTask@70eb7859 task result= java.util.concurrent.FutureTask@732a54f9 task result= java.util.concurrent.FutureTask@6030e280 task result= java.util.concurrent.FutureTask@296672d6 task result= java.util.concurrent.FutureTask@4fd54d6 task result= java.util.concurrent.FutureTask@13ccb029 task result= java.util.concurrent.FutureTask@63415de6 task result= java.util.concurrent.FutureTask@587bd9f2 task result= java.util.concurrent.FutureTask@2b21cc40 task result= java.util.concurrent.FutureTask@37e893df here java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222) at java.util.concurrent.FutureTask.get(FutureTask.java:83) at codeTest.ThreadTest2.threadTestAll(ThreadTest2.java:48) at codeTest.ThreadTest2.main(ThreadTest2.java:30) Caused by: java.lang.NullPointerException at codeTest.ThreadTest2$myTask.call(ThreadTest2.java:91) at codeTest.ThreadTest2$myTask.call(ThreadTest2.java:1) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) ```
Jacob,初始化ActiveXComponent 操作word
1. Exception in thread "main" java.lang.ExceptionInInitializerError at Jacob.<init>(Jacob.java:34) at Jacob.main(Jacob.java:347) Caused by: java.lang.IllegalStateException: Can't find META-INF/JacobVersion.properties using JacobReleaseInfo.class.getClassLoader().getResourceAsStream() at com.jacob.com.JacobReleaseInfo.loadVersionProperties(JacobReleaseInfo.java:55) at com.jacob.com.JacobReleaseInfo.getBuildVersion(JacobReleaseInfo.java:91) at com.jacob.com.LibraryLoader.getPreferredDLLName(LibraryLoader.java:199) at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:178) at com.jacob.com.JacobObject.<clinit>(JacobObject.java:107) ... 2 more
多线程运行,cpu使用率过高
1 使用Fork/Join,类似代码如下,运行起来,CPU过高 public class MyTask extends RecursiveTask<Integer> { private static final long serialVersionUID = 1103203544619621157L; int THRESHOLD = 100;int start;int end; int[] arr; public MyTask(int[] arr,int start,int end){ this.arr = arr; this.start = start; this.end = end; } @Override protected Integer compute() { if(end - start <= THRESHOLD){ int sum = 0; for(int i= start;i<end;i++){ sum += arr[i]; } return sum; } int mid = (end + start)/2; MyTask t1 = new MyTask(arr,start,mid); MyTask t2 = new MyTask(arr,mid,end); invokeAll(t1, t2); return t1.join() + t2.join(); } public static void main(String args){ int[] arr = new int[5000]; random(arr); ForkJoinPool pool = new ForkJoinPool(); MyTask task = new MyTask(arr,0,arr.length); pool.invoke(task); } } 2 堆栈信息如下 "ForkJoinPool-1-worker-8" daemon prio=10 tid=0x00007fab88001000 nid=0x32d4 waiting on condition [0x00007fac178b7000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070b86f138> (a java.util.concurrent.ForkJoinPool) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.ForkJoinPool.tryAwaitWork(ForkJoinPool.java:864) at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:647) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398) "ForkJoinPool-1-worker-6" daemon prio=10 tid=0x00007fab8c004800 nid=0x32d2 waiting on condition [0x00007fac17ab9000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070b86f138> (a java.util.concurrent.ForkJoinPool) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.ForkJoinPool.tryAwaitWork(ForkJoinPool.java:864) at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:647) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398) "ForkJoinPool-1-worker-5" daemon prio=10 tid=0x00007fab90003000 nid=0x32d1 waiting on condition [0x00007fac17bba000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070b86f138> (a java.util.concurrent.ForkJoinPool) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.ForkJoinPool.tryAwaitWork(ForkJoinPool.java:864) at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:647) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398) "ForkJoinPool-1-worker-4" daemon prio=10 tid=0x00007fab90001000 nid=0x32d0 waiting on condition [0x00007fac17cbb000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070b86f138> (a java.util.concurrent.ForkJoinPool) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226) at java.util.concurrent.ForkJoinPool.idleAwaitWork(ForkJoinPool.java:894) at java.util.concurrent.ForkJoinPool.tryAwaitWork(ForkJoinPool.java:830) at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:647) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398) "ForkJoinPool-1-worker-2" daemon prio=10 tid=0x00007fab8c001000 nid=0x32ce waiting on condition [0x00007fac17ebd000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070b86f138> (a java.util.concurrent.ForkJoinPool) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.ForkJoinPool.tryAwaitWork(ForkJoinPool.java:864) at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:647) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398) "http-bio-3080-exec-10" daemon prio=10 tid=0x00007fabc8007000 nid=0x32b5 waiting on condition [0x00007fac34260000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070bac9f78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) "http-bio-3080-exec-9" daemon prio=10 tid=0x00007fabc8005000 nid=0x32b4 waiting on condition [0x00007fac34361000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070bac9f78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) "http-bio-3080-exec-8" daemon prio=10 tid=0x00007fabc8003800 nid=0x32b3 waiting on condition [0x00007fac34462000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070bac9f78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) "http-bio-3080-exec-7" daemon prio=10 tid=0x00007faba4001000 nid=0x32b2 waiting on condition [0x00007fac34563000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x000000070bac9f78> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104) at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) ![图片说明](https://img-ask.csdn.net/upload/201906/28/1561714492_127107.png)
Storm运行main方法出错
Exception in thread "main" java.lang.IllegalAccessError: tried to access method clojure.lang.RT.classForNameNonLoading(Ljava/lang/String;)Ljava/lang/Class; from class org.apache.storm.daemon.nimbus$loading__5340__auto____6155 at org.apache.storm.daemon.nimbus$loading__5340__auto____6155.invoke(nimbus.clj:16) at org.apache.storm.daemon.nimbus__init.load(Unknown Source) at org.apache.storm.daemon.nimbus__init.<clinit>(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:278) at clojure.lang.RT.loadClassForName(RT.java:2098) at clojure.lang.RT.load(RT.java:430) at clojure.lang.RT.load(RT.java:411) at clojure.core$load$fn__5018.invoke(core.clj:5530) at clojure.core$load.doInvoke(core.clj:5529) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.core$load_one.invoke(core.clj:5336) at clojure.core$load_lib$fn__4967.invoke(core.clj:5375) at clojure.core$load_lib.doInvoke(core.clj:5374) at clojure.lang.RestFn.applyTo(RestFn.java:142) at clojure.core$apply.invoke(core.clj:619) at clojure.core$load_libs.doInvoke(core.clj:5417) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invoke(core.clj:619) at clojure.core$require.doInvoke(core.clj:5496) at clojure.lang.RestFn.invoke(RestFn.java:408) at org.apache.storm.testing$loading__5340__auto____6153.invoke(testing.clj:17) at org.apache.storm.testing__init.load(Unknown Source) at org.apache.storm.testing__init.<clinit>(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:278) at clojure.lang.RT.loadClassForName(RT.java:2098) at clojure.lang.RT.load(RT.java:430) at clojure.lang.RT.load(RT.java:411)
怎么解决,跪求解答,错误信息如下
10-20 17:58:21.836: W/dalvikvm(7106): threadid=1: thread exiting with uncaught exception (group=0xa616c908) 10-20 17:58:21.840: E/AndroidRuntime(7106): FATAL EXCEPTION: main 10-20 17:58:21.840: E/AndroidRuntime(7106): java.lang.VerifyError: com/example/app/admin/Admin_Draw 10-20 17:58:21.840: E/AndroidRuntime(7106): at java.lang.Class.newInstanceImpl(Native Method) 10-20 17:58:21.840: E/AndroidRuntime(7106): at java.lang.Class.newInstance(Class.java:1319) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.app.Instrumentation.newActivity(Instrumentation.java:1066) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2254) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.app.ActivityThread.access$600(ActivityThread.java:141) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.os.Handler.dispatchMessage(Handler.java:99) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.os.Looper.loop(Looper.java:137) 10-20 17:58:21.840: E/AndroidRuntime(7106): at android.app.ActivityThread.main(ActivityThread.java:5069) 10-20 17:58:21.840: E/AndroidRuntime(7106): at java.lang.reflect.Method.invokeNative(Native Method) 10-20 17:58:21.840: E/AndroidRuntime(7106): at java.lang.reflect.Method.invoke(Method.java:511) 10-20 17:58:21.840: E/AndroidRuntime(7106): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 10-20 17:58:21.840: E/AndroidRuntime(7106): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 10-20 17:58:21.840: E/AndroidRuntime(7106): at dalvik.system.NativeStart.main(Native Method)
请求:java写的客户端发送数据失败!!
连接时,给服务端发送数据时总是报错!! 11-28 11:15:36.164: D/MainActivity(4212): wifiname:"LcyAP_03001" prxFlag:true substr: LcyAP FirstConn:true 11-28 11:15:36.164: D/MainActivity(4212): Now Ready to create connect to LC:Now wifi stat is:SSID:"LcyAP_03001"wificonnsetat:trueSrvIp:192.168.173.1 11-28 11:15:36.164: W/System.err(4212): java.net.SocketException: Socket is closed 11-28 11:15:36.174: W/System.err(4212): at java.net.Socket.checkOpenAndCreate(Socket.java:675) 11-28 11:15:36.174: W/System.err(4212): at java.net.Socket.getOutputStream(Socket.java:415) 11-28 11:15:36.174: W/System.err(4212): at cn.LCSys.socket.TCPClient.sendMsg(TCPClient.java:104) 11-28 11:15:36.174: W/System.err(4212): at cn.LCSys.MainActivity$4.run(MainActivity.java:410) 11-28 11:15:36.174: W/System.err(4212): at java.lang.Thread.run(Thread.java:841) 11-28 11:15:38.194: D/MainActivity(4212): wifiname:"LcyAP_03001" prxFlag:true substr: LcyAP FirstConn:true 11-28 11:15:38.194: D/MainActivity(4212): Now Ready to create connect to LC:Now wifi stat is:SSID:"LcyAP_03001"wificonnsetat:trueSrvIp:192.168.173.1 11-28 11:15:38.194: W/System.err(4212): java.net.SocketException: Socket is closed 11-28 11:15:38.194: W/System.err(4212): at java.net.Socket.checkOpenAndCreate(Socket.java:675) 11-28 11:15:38.194: W/System.err(4212): at java.net.Socket.getOutputStream(Socket.java:415) 11-28 11:15:38.194: W/System.err(4212): at cn.LCSys.socket.TCPClient.sendMsg(TCPClient.java:104) 11-28 11:15:38.194: W/System.err(4212): at cn.LCSys.MainActivity$4.run(MainActivity.java:410) 11-28 11:15:38.204: W/System.err(4212): at java.lang.Thread.run(Thread.java:841) 客户端代码为: package cn.LCSys.socket; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; import java.net.Socket; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import cn.LCSys.MainActivity; import cn.LCSys.fragment.SystemSetting; import android.content.Intent; import android.os.SystemClock; import android.util.Log; public class TCPClient { private String TAG = "TCP Client"; private static TCPClient s_Tcp = null; // 要连接的服务器Ip地址 private String SrvIp; // 要连接的远程服务器在监听的端口 private int SrvPort; public boolean isInitialized = false; private boolean bConnect; Socket socket = null ; private long LastTickCount; public static synchronized TCPClient instance() { if (s_Tcp == null) { { s_Tcp = new TCPClient(Const.SOCKET_SERVER, Const.SOCKET_PORT); } } return s_Tcp; } public TCPClient(String HostIp, int HostListenningPort) { LastTickCount = 0; Log.d(TAG,"SrvIP:["+HostIp+"]SrvPort:["+HostListenningPort+"]."); this.SrvIp = HostIp; this.SrvPort = HostListenningPort; bConnect = false; try { start(); } catch (Exception e) { this.isInitialized = false; Log.d(TAG," TCPClient Initialize catch err!"+e.getMessage()); e.printStackTrace(); } } public static final Object locked = new Object(); public static final BlockingQueue<String> queue = new ArrayBlockingQueue<String>( 1024 * 100); //通过数据接收判断是否链路正常 10秒没有数据认为链路异常,进行重新连接 class EchoThread extends Thread{ private Socket socket; @Override public void run() { while(isInitialized){ try { if(LastTickCount > 0) { //10 if((System.currentTimeMillis() - LastTickCount) > Const.SOCKET_TIMOUT) { bConnect = false; LastTickCount = 0; } } SystemClock.sleep(500); } catch (Exception e) { e.printStackTrace(); } } } } //发送数据 public boolean sendMsg(String sendMsg) throws InterruptedException{ try { PrintWriter pw = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); pw.write(sendMsg); pw.flush(); return true; } catch (Exception e) { bConnect = false; e.printStackTrace(); return false; } } //} // 接收数据的线程 class ReceiveThread extends Thread { private Socket socket; public ReceiveThread(Socket socket) { this.socket = socket; } @Override public void run() { String receivedString; CharBuffer charBuffer = CharBuffer.allocate(4096); while(isInitialized){ try { Reader reader = new InputStreamReader(socket.getInputStream()); charBuffer.clear(); int index = -1; while((index=reader.read(charBuffer))!=-1) { LastTickCount = System.currentTimeMillis(); charBuffer.flip(); //System.out.println("client:"+charBuffer.toString()); Charset cs = Charset.forName("UTF-8"); receivedString = cs.encode(charBuffer).toString() ; int readlen = receivedString.length(); if( readlen > 100) { //无法获取到数据 /*receivedString = Charset.forName("US-ASCII") .newDecoder().decode(buffer).toString();*/ // mylcHandle.ColldataHandle(receivedString); Log.d(TAG,"Read Data Length: "+readlen); } else { Log.d(TAG, "Recv len:"+readlen+" Content:"+receivedString); } Intent i = new Intent(Const.BC);//广播消息,实现类之间的交互 i.putExtra("response", receivedString); MainActivity.s_context.sendBroadcast(i); //给系统配置广播数据 if(null!= SystemSetting.s_context) { Log.d(TAG, "Broad to SystemSetting:"+readlen); SystemSetting.s_context.sendBroadcast(i); } //给实时数据fragement广播数据 /* if(null!= FragmentRealData.s_context) { Intent ii = new Intent(Const.DATABC); ii.putExtra("response", receivedString); Log.d(TAG, "Broad to FragmentRealData:"+readlen); FragmentRealData.s_context.sendBroadcast(ii); }*/ charBuffer.clear(); } } catch (Exception e) { e.printStackTrace(); } } } } public void start() throws UnknownHostException, IOException{ socket = new Socket(SrvIp,SrvPort); if(socket != null) { bConnect = true; isInitialized = true; new ReceiveThread(socket).start(); } else { bConnect = false; } } boolean isConnect() { return bConnect; } public void closeTCPSocket() { try{ if(socket!= null) { socket.close(); isInitialized = false; } } catch(Exception ex) { Log.e(TAG,"Close Socket error!"); } } // public static void main(String[] args) throws UnknownHostException, IOException { // new TCPClient().start(); // } }
eclipse中tomcat关闭和重启问题
java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at java.net.Socket.<init>(Socket.java:425) at java.net.Socket.<init>(Socket.java:241) at org.apache.jk.common.ChannelSocket.unLockSocket(ChannelSocket.java:492) at org.apache.jk.common.ChannelSocket.pause(ChannelSocket.java:288) at org.apache.jk.server.JkMain.pause(JkMain.java:739) at org.apache.jk.server.JkCoyoteHandler.pause(JkCoyoteHandler.java:153) at org.apache.catalina.connector.Connector.pause(Connector.java:1138) at org.apache.catalina.core.StandardService.stop(StandardService.java:578) at org.apache.catalina.core.StandardServer.stop(StandardServer.java:793) at org.apache.catalina.startup.Catalina.stop(Catalina.java:662) at org.apache.catalina.startup.Catalina.start(Catalina.java:629) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) 三月 15, 2017 10:04:17 下午 org.apache.catalina.core.StandardService stop 信息: Stopping service Catalina 三月 15, 2017 10:04:17 下午 org.apache.coyote.http11.Http11Protocol destroy 信息: Stopping Coyote HTTP/1.1 on http-8080 Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/ParameterizedMessage at org.apache.logging.log4j.message.ParameterizedMessageFactory.newMessage(ParameterizedMessageFactory.java:47) at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:737) at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:708) at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:314) at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:77) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.message.ParameterizedMessage at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) ... 6 more 在eclipse中停止tomcat出现以上错误,求大神解答
当进度对话框和后台线程活动的时候如何处理屏幕的方向的变化?
我的程序是在一个后台的线程里进行网络活动。在开始之前,它弹出一个进度对话框。这个对话框是处理器上被驳回的。除了当对话框出现的时候屏幕的方向发生变换(后台线程也跟随着发生变化),其他的都是正常的。在时,应用或者崩溃,有时候死锁,或者是当所有的线程都被杀死的时候进入到应用,否则一点都不起作用这样一个怪异的阶段。 我能怎样处理屏幕方向发生变化这个问题? 下面的示例代码大概就是我的真正的程序: public class MyAct extends Activity implements Runnable { public ProgressDialog mProgress; // UI has a button that when pressed calls send public void send() { mProgress = ProgressDialog.show(this, "Please wait", "Please wait", true, true); Thread thread = new Thread(this); thread.start(); } public void run() { Thread.sleep(10000); Message msg = new Message(); mHandler.sendMessage(msg); } private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { mProgress.dismiss(); } }; } 栈: E/WindowManager( 244): Activity MyAct has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@433b7150 that was originally added here E/WindowManager( 244): android.view.WindowLeaked: Activity MyAct has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@433b7150 that was originally added here E/WindowManager( 244): at android.view.ViewRoot.<init>(ViewRoot.java:178) E/WindowManager( 244): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:147) E/WindowManager( 244): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:90) E/WindowManager( 244): at android.view.Window$LocalWindowManager.addView(Window.java:393) E/WindowManager( 244): at android.app.Dialog.show(Dialog.java:212) E/WindowManager( 244): at android.app.ProgressDialog.show(ProgressDialog.java:103) E/WindowManager( 244): at android.app.ProgressDialog.show(ProgressDialog.java:91) E/WindowManager( 244): at MyAct.send(MyAct.java:294) E/WindowManager( 244): at MyAct$4.onClick(MyAct.java:174) E/WindowManager( 244): at android.view.View.performClick(View.java:2129) E/WindowManager( 244): at android.view.View.onTouchEvent(View.java:3543) E/WindowManager( 244): at android.widget.TextView.onTouchEvent(TextView.java:4664) E/WindowManager( 244): at android.view.View.dispatchTouchEvent(View.java:3198) E/WindowManager( 244): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) E/WindowManager( 244): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) E/WindowManager( 244): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) E/WindowManager( 244): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) E/WindowManager( 244): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) E/WindowManager( 244): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1593) E/WindowManager( 244): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1089) E/WindowManager( 244): at android.app.Activity.dispatchTouchEvent(Activity.java:1871) E/WindowManager( 244): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1577) E/WindowManager( 244): at android.view.ViewRoot.handleMessage(ViewRoot.java:1140) E/WindowManager( 244): at android.os.Handler.dispatchMessage(Handler.java:88) E/WindowManager( 244): at android.os.Looper.loop(Looper.java:123) E/WindowManager( 244): at android.app.ActivityThread.main(ActivityThread.java:3739) E/WindowManager( 244): at java.lang.reflect.Method.invokeNative(Native Method) E/WindowManager( 244): at java.lang.reflect.Method.invoke(Method.java:515) E/WindowManager( 244): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) E/WindowManager( 244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) E/WindowManager( 244): at dalvik.system.NativeStart.main(Native Method) 和: W/dalvikvm( 244): threadid=3: thread exiting with uncaught exception (group=0x4000fe68) E/AndroidRuntime( 244): Uncaught handler: thread main exiting due to uncaught exception E/AndroidRuntime( 244): java.lang.IllegalArgumentException: View not attached to window manager E/AndroidRuntime( 244): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:331) E/AndroidRuntime( 244): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200) E/AndroidRuntime( 244): at android.view.Window$LocalWindowManager.removeView(Window.java:401) E/AndroidRuntime( 244): at android.app.Dialog.dismissDialog(Dialog.java:249) E/AndroidRuntime( 244): at android.app.Dialog.access$000(Dialog.java:59) E/AndroidRuntime( 244): at android.app.Dialog$1.run(Dialog.java:93) E/AndroidRuntime( 244): at android.app.Dialog.dismiss(Dialog.java:233) E/AndroidRuntime( 244): at MyAct$1.handleMessage(MyAct.java:321) E/AndroidRuntime( 244): at android.os.Handler.dispatchMessage(Handler.java:88) E/AndroidRuntime( 244): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 244): at android.app.ActivityThread.main(ActivityThread.java:3739) E/AndroidRuntime( 244): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 244): at java.lang.reflect.Method.invoke(Method.java:515) E/AndroidRuntime( 244): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) E/AndroidRuntime( 244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) E/AndroidRuntime( 244): at dalvik.system.NativeStart.main(Native Method) I/Process ( 46): Sending signal. PID: 244 SIG: 3 I/dalvikvm( 244): threadid=7: reacting to signal 3 I/dalvikvm( 244): Wrote stack trace to '/data/anr/traces.txt' I/Process ( 244): Sending signal. PID: 244 SIG: 9 I/ActivityManager( 46): Process MyAct (pid 244) has died. 我试图在onSaveInstanceState上取消对话框的进度条,但是这只能防止立即崩溃。后台线程仍然在运行,而且这个用户界面有一部分是处于拉伸状态的。需要杀掉整个应用程序才会重新开始工作。
请问为什么我只要在android studio中加入线程就会程序就会闪退呀?
下面是MainActivity的代码。 ``` package wjsd.sfy.suyan.test; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.ProgressBar; public class MainActivity extends AppCompatActivity { private ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar); // private TextView textView = (TextView)findViewById(R.id.textView); private Button button = (Button)findViewById(R.id.button); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button.setOnClickListener(new ButtonListener()); } class ButtonListener implements View.OnClickListener{ @Override public void onClick(View v) { MyThread myThread = new MyThread(); myThread.start(); } } class MyThread extends Thread{ @Override public void run() { for(int i = 0;i < 100;i++){ try { Thread.sleep(100); }catch (Exception e){ e.printStackTrace(); } progressBar.setProgress(progressBar.getProgress() + 1); } } } } ``` 下面是错误信息: 07-24 07:41:57.002 4672-4672/wjsd.sfy.suyan.test W/System: ClassLoader referenced unknown path: /data/app/wjsd.sfy.suyan.test-1/lib/x86_64 07-24 07:41:57.066 4672-4672/wjsd.sfy.suyan.test D/AndroidRuntime: Shutting down VM 07-24 07:41:57.066 4672-4672/wjsd.sfy.suyan.test E/AndroidRuntime: FATAL EXCEPTION: main Process: wjsd.sfy.suyan.test, PID: 4672 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{wjsd.sfy.suyan.test/wjsd.sfy.suyan.test.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:68) at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146) at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28) at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41) at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:188) at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:172) at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:512) at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:184) at wjsd.sfy.suyan.test.MainActivity.<init>(MainActivity.java:10) at java.lang.Class.newInstance(Native Method) at android.app.Instrumentation.newActivity(Instrumentation.java:1067) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  07-24 07:42:00.272 4672-4672/wjsd.sfy.suyan.test I/Process: Sending signal. PID: 4672 SIG: 9 求教,谢谢了。
动态规划入门到熟悉,看不懂来打我啊
持续更新。。。。。。 2.1斐波那契系列问题 2.2矩阵系列问题 2.3跳跃系列问题 3.1 01背包 3.2 完全背包 3.3多重背包 3.4 一些变形选讲 2.1斐波那契系列问题 在数学上,斐波纳契数列以如下被以递归的方法定义:F(0)=0,F(1)=1, F(n)=F(n-1)+F(n-2)(n&gt;=2,n∈N*)根据定义,前十项为1, 1, 2, 3...
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)
最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成) one 樱花树 动态生成樱花 效果图(这个是动态的): 实现代码 import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch, ...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
shell脚本:备份数据库、代码上线
备份MySQL数据库 场景: 一台MySQL服务器,跑着5个数据库,在没有做主从的情况下,需要对这5个库进行备份 需求: 1)每天备份一次,需要备份所有的库 2)把备份数据存放到/data/backup/下 3)备份文件名称格式示例:dbname-2019-11-23.sql 4)需要对1天以前的所有sql文件压缩,格式为gzip 5)本地数据保留1周 6)需要把备份的数据同步到远程备份中心,假如...
如何安装 IntelliJ IDEA 最新版本——详细教程
IntelliJ IDEA 简称 IDEA,被业界公认为最好的 Java 集成开发工具,尤其在智能代码助手、代码自动提示、代码重构、代码版本管理(Git、SVN、Maven)、单元测试、代码分析等方面有着亮眼的发挥。IDEA 产于捷克,开发人员以严谨著称的东欧程序员为主。IDEA 分为社区版和付费版两个版本。 我呢,一直是 Eclipse 的忠实粉丝,差不多十年的老用户了。很早就接触到了 IDEA...
面试还搞不懂redis,快看看这40道面试题(含答案和思维导图)
Redis 面试题 1、什么是 Redis?. 2、Redis 的数据类型? 3、使用 Redis 有哪些好处? 4、Redis 相比 Memcached 有哪些优势? 5、Memcache 与 Redis 的区别都有哪些? 6、Redis 是单进程单线程的? 7、一个字符串类型的值能存储最大容量是多少? 8、Redis 的持久化机制是什么?各自的优缺点? 9、Redis 常见性...
为什么要推荐大家学习字节码?
配套视频: 为什么推荐大家学习Java字节码 https://www.bilibili.com/video/av77600176/ 一、背景 本文主要探讨:为什么要学习 JVM 字节码? 可能很多人会觉得没必要,因为平时开发用不到,而且不学这个也没耽误学习。 但是这里分享一点感悟,即人总是根据自己已经掌握的知识和技能来解决问题的。 这里有个悖论,有时候你觉得有些技术没用恰恰是...
【设计模式】单例模式的八种写法分析
网上泛滥流传单例模式的写法种类,有说7种的,也有说6种的,当然也不排除说5种的,他们说的有错吗?其实没有对与错,刨根问底,写法终究是写法,其本质精髓大体一致!因此完全没必要去追究写法的多少,有这个时间还不如跟着宜春去网吧偷耳机、去田里抓青蛙得了,一天天的....
《面试宝典》:检验是否为合格的初中级程序员的面试知识点,你都知道了吗?查漏补缺
欢迎关注文章系列,一起学习 《提升能力,涨薪可待篇》 《面试知识,工作可待篇》 《实战演练,拒绝996篇》 也欢迎关注公 众 号【Ccww笔记】,原创技术文章第一时间推出 如果此文对你有帮助、喜欢的话,那就点个赞呗,点个关注呗! 《面试知识,工作可待篇》-Java笔试面试基础知识大全 前言 是不是感觉找工作面试是那么难呢? 在找工作面试应在学习的基础进行总结面试知识点,工作也指日可待,欢...
在阿里,40岁的奋斗姿势
在阿里,40岁的奋斗姿势 在阿里,什么样的年纪可以称为老呢?35岁? 在云网络,有这样一群人,他们的平均年龄接近40,却刚刚开辟职业生涯的第二战场。 他们的奋斗姿势是什么样的呢? 洛神赋 “翩若惊鸿,婉若游龙。荣曜秋菊,华茂春松。髣髴兮若轻云之蔽月,飘飖兮若流风之回雪。远而望之,皎若太阳升朝霞;迫而察之,灼若芙蕖出渌波。” 爱洛神,爱阿里云 2018年,阿里云网络产品部门启动洛神2.0升...
【超详细分析】关于三次握手与四次挥手面试官想考我们什么?
在面试中,三次握手和四次挥手可以说是问的最频繁的一个知识点了,我相信大家也都看过很多关于三次握手与四次挥手的文章,今天的这篇文章,重点是围绕着面试,我们应该掌握哪些比较重要的点,哪些是比较被面试官给问到的,我觉得如果你能把我下面列举的一些点都记住、理解,我想就差不多了。 三次握手 当面试官问你为什么需要有三次握手、三次握手的作用、讲讲三次三次握手的时候,我想很多人会这样回答: 首先很多人会先讲下握...
压测学习总结(1)——高并发性能指标:QPS、TPS、RT、吞吐量详解
一、QPS,每秒查询 QPS:Queries Per Second意思是“每秒查询率”,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。互联网中,作为域名系统服务器的机器的性能经常用每秒查询率来衡量。 二、TPS,每秒事务 TPS:是TransactionsPerSecond的缩写,也就是事务数/秒。它是软件测试结果的测量单位。一个事务是指一...
新程序员七宗罪
当我发表这篇文章《为什么每个工程师都应该开始考虑开发中的分析和编程技能呢?》时,我从未想到它会对读者产生如此积极的影响。那些想要开始探索编程和数据科学领域的人向我寻求建议;还有一些人问我下一篇文章的发布日期;还有许多人询问如何顺利过渡到这个职业。我非常鼓励大家继续分享我在这个旅程的经验,学习,成功和失败,以帮助尽可能多的人过渡到一个充满无数好处和机会的职业生涯。亲爱的读者,谢谢你。 -罗伯特。 ...
活到老,学到老,程序员也该如此
全文共2763字,预计学习时长8分钟 图片来源:Pixabay 此前,“网传阿里巴巴要求尽快实现P8全员35周岁以内”的消息闹得沸沸扬扬。虽然很快被阿里辟谣,但苍蝇不叮无缝的蛋,无蜜不招彩蝶蜂。消息从何而来?真相究竟怎样?我们无从而知。我们只知道一个事实:不知从何时开始,程序猿也被划在了“吃青春饭”行业之列。 饱受“996ICU”摧残后,好不容易“头秃了变强了”,即将步入为“高...
2019年Spring Boot面试都问了什么?快看看这22道面试题!
Spring Boot 面试题 1、什么是 Spring Boot? 2、Spring Boot 有哪些优点? 3、什么是 JavaConfig? 4、如何重新加载 Spring Boot 上的更改,而无需重新启动服务器? 5、Spring Boot 中的监视器是什么? 6、如何在 Spring Boot 中禁用 Actuator 端点安全性? 7、如何在自定义端口上运行 Sprin...
小白学 Python 爬虫(5):前置准备(四)数据库基础
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Linux基础入门 小白学 Python 爬虫(4):前置准备(三)Docker基础入门 本篇文章,我们接着介绍基础内容,数据库。 爬虫将数据爬取完成后,总要有地方存放吧,这个数据存在哪里呢? ...
面试官:关于Java性能优化,你有什么技巧
通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。 一般有两种方案:即优化代码或更改设计方法。我们一般会选择后者,因为不去调用以下代码要比调用一些优化的代码更能提高程序的性能。而一个设计良好的程序能够精简代码,从而提高性能。 下面将提供一些在JAVA程序的设计和编码中,为了能够提高JAVA程序的性能,而经常采用的一些方法和技巧。 1.对象的生成和大小的调整。 J...
JavaScript 中, 5 种增加代码可读性的最佳实践
作者:Milos Protic 译者:前端小智 来源:blog.risingstack 为了保证的可读性,本文采用意译而非直译。 简介 如果咱们关注代码本身结构及可读笥,而不是只关心它是否能工作,那么咱们写代码是有一定的水准。专业开发人员将为未来的自己和“其他人”编写代码,而不仅仅只编写能应付当前工作的代码。 在此基础上,可读性高的代码可以定义为自解释的、易于人理解的、易于更改...
【图解算法面试】记一次面试:说说游戏中的敏感词过滤是如何实现的?
版权声明:本文为苦逼的码农原创。未经同意禁止任何形式转载,特别是那些复制粘贴到别的平台的,否则,必定追究。欢迎大家多多转发,谢谢。 小秋今天去面试了,面试官问了一个与敏感词过滤算法相关的问题,然而小秋对敏感词过滤算法一点也没听说过。于是,有了下下事情的发生… 面试官开怼 面试官:玩过王者荣耀吧?了解过敏感词过滤吗?,例如在游戏里,如果我们发送“你在干嘛?麻痹演员啊你?”,由于“麻痹”是一个敏感词,...
程序员需要了解的硬核知识之汇编语言(一)
之前的系列文章从 CPU 和内存方面简单介绍了一下汇编语言,但是还没有系统的了解一下汇编语言,汇编语言作为第二代计算机语言,会用一些容易理解和记忆的字母,单词来代替一个特定的指令,作为高级编程语言的基础,有必要系统的了解一下汇编语言,那么本篇文章希望大家跟我一起来了解一下汇编语言。 汇编语言和本地代码 我们在之前的文章中探讨过,计算机 CPU 只能运行本地代码(机器语言)程序,用 C 语言等高级语...
GitHub 标星 1.6w+,我发现了一个宝藏项目,作为编程新手有福了!
大家好,我是 Rocky0429,一个最近老在 GitHub 上闲逛的蒟蒻… 特别惭愧的是,虽然我很早就知道 GitHub,但是学会逛 GitHub 的时间特别晚。当时一方面是因为菜,看着这种全是英文的东西难受,不知道该怎么去玩,另一方面是一直在搞 ACM,没有做一些工程类的项目,所以想当然的以为和 GitHub 也没什么关系(当然这种想法是错误的)。 后来自己花了一个星期看完了 Pyt...
Java知识体系最强总结(2020版)
更新于2019-12-15 10:38:00 本人从事Java开发已多年,平时有记录问题解决方案和总结知识点的习惯,整理了一些有关Java的知识体系,这不是最终版,会不定期的更新。也算是记录自己在从事编程工作的成长足迹,通过博客可以促进博主与阅读者的共同进步,结交更多志同道合的朋友。特此分享给大家,本人见识有限,写的博客难免有错误或者疏忽的地方,还望各位大佬指点,在此表示感激不尽。 文章目录...
计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
介绍几个可以下载编程电子书籍的网站。 1.Github Github上编程书资源很多,你可以根据类型和语言去搜索。推荐几个热门的: free-programming-books-zh_CN:58K 星的GitHub,编程语言、WEB、函数、大数据、操作系统、在线课程、数据库相关书籍应有尽有,共有几百本。 Go语言高级编程:涵盖CGO,Go汇编语言,RPC实现,Protobuf插件实现,Web框架实...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
Fiddler+夜神模拟器进行APP抓包
Fiddler+夜神模拟器进行APP抓包 作者:霞落满天 需求:对公司APP进行抓包获取详细的接口信息,这是现在开发必备的。 工具:Fiddler抓包,夜神模拟器 模拟手机 安装APP 1.下载Fiddler https://www.telerik.com/download/fiddler Fiddler正是在这里帮助您记录计算机和Internet之间传递的所有HTTP和HTTPS通信...
相关热词 c#时间格式化 不带- c#替换字符串中指定位置 c# rdlc 动态报表 c# 获取txt编码格式 c#事件主动调用 c#抽象工厂模式 c# 如何添加类注释 c# static块 c#处理浮点数 c# 生成字母数字随机数
立即提问