先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
正文
-
*
-
*
-
* @see java.lang.Thread#run()
-
*/
-
public abstract void run();
-
}
Callable与Runnable的功能大致相似,Callable中有一个call()函数,但是call()函数有返回值,而Runnable的run()函数不能将结果返回给客户程序。Callable的声明如下 :
[java] view plain copy
-
public interface Callable {
-
/**
-
* Computes a result, or throws an exception if unable to do so.
-
*
-
* @return computed result
-
* @throws Exception if unable to compute a result
-
*/
-
V call() throws Exception;
-
}
可以看到,这是一个泛型接口,call()函数返回的类型就是客户程序传递进来的V类型。
Executor就是Runnable和Callable的调度容器,Future就是对于具体的Runnable或者Callable任务的执行结果进行
**取消、**查询是否完成、获取结果、设置结果操作。get方法会阻塞,直到任务返回结果(Future简介)。Future声明如下 :
[java] view plain copy
-
/**
-
* @see FutureTask
-
* @see Executor
-
* @since 1.5
-
* @author Doug Lea
-
* @param The result type returned by this Future’s get method
-
*/
-
public interface Future {
-
/**
-
* Attempts to cancel execution of this task. This attempt will
-
* fail if the task has already completed, has already been cancelled,
-
* or could not be cancelled for some other reason. If successful,
-
* and this task has not started when cancel is called,
-
* this task should never run. If the task has already started,
-
* then the mayInterruptIfRunning parameter determines
-
* whether the thread executing this task should be interrupted in
-
* an attempt to stop the task. *
-
*/
-
boolean cancel(boolean mayInterruptIfRunning);
-
/**
-
* Returns true if this task was cancelled before it completed
-
* normally.
-
*/
-
boolean isCancelled();
-
/**
-
* Returns true if this task completed.
-
*
-
*/
-
boolean isDone();
-
/**
-
* Waits if necessary for the computation to complete, and then
-
* retrieves its result.
-
*
-
* @return the computed result
-
*/
-
V get() throws InterruptedException, ExecutionException;
-
/**
-
* Waits if necessary for at most the given time for the computation
-
* to complete, and then retrieves its result, if available.
-
*
-
* @param timeout the maximum time to wait
-
* @param unit the time unit of the timeout argument
-
* @return the computed result
-
*/
-
V get(long timeout, TimeUnit unit)
-
throws InterruptedException, ExecutionException, TimeoutException;
-
}
FutureTask则是一个RunnableFuture,而RunnableFuture实现了Runnbale又实现了Futrue这两个接口,
[java] view plain copy
- public class FutureTask implements RunnableFuture
RunnableFuture
[java] view plain copy
-
public interface RunnableFuture extends Runnable, Future {
-
/**
-
* Sets this Future to the result of its computation
-
* unless it has been cancelled.
-
*/
-
void run();
-
}
另外它还可以包装Runnable和Callable, 由构造函数注入依赖。
[java] view plain copy
-
public FutureTask(Callable callable) {
-
if (callable == null)
-
throw new NullPointerException();
-
this.callable = callable;
-
this.state = NEW; // ensure visibility of callable
-
}
-
public FutureTask(Runnable runnable, V result) {
-
this.callable = Executors.callable(runnable, result);
-
this.state = NEW; // ensure visibility of callable
-
}
可以看到,Runnable注入会被Executors.callable()函数转换为Callable类型,即FutureTask最终都是执行Callable类型的任务。该适配函数的实现如下 :
[java] view plain copy
-
public static Callable callable(Runnable task, T result) {
-
if (task == null)
-
throw new NullPointerException();
-
return new RunnableAdapter(task, result);
-
}
RunnableAdapter适配器
[java] view plain copy
-
/**
-
* A callable that runs given task and returns given result
-
*/
-
static final class RunnableAdapter implements Callable {
-
final Runnable task;
-
final T result;
-
RunnableAdapter(Runnable task, T result) {
-
this.task = task;
-
this.result = result;
-
}
-
public T call() {
-
task.run();
-
return result;
-
}
-
}
由于FutureTask实现了Runnable,因此它既可以通过Thread包装来直接执行,也可以提交给ExecuteService来执行。
并且还可以直接通过get()函数获取执行结果,该函数会阻塞,直到结果返回。因此FutureTask既是Future、
**Runnable,**又是包装了Callable( 如果是Runnable最终也会被转换为Callable ), 它是这两者的合体。
[java] view plain copy
-
package com.effective.java.concurrent.task;
-
import java.util.concurrent.Callable;
-
import java.util.concurrent.ExecutionException;
-
import java.util.concurrent.ExecutorService;
-
import java.util.concurrent.Executors;
-
import java.util.concurrent.Future;
-
import java.util.concurrent.FutureTask;
-
/**
-
*
-
* @author mrsimple
-
*
-
*/
最后
现在正是金三银四的春招高潮,前阵子小编一直在搭建自己的网站,并整理了全套的**【一线互联网大厂Java核心面试题库+解析】:包括Java基础、异常、集合、并发编程、JVM、Spring全家桶、MyBatis、Redis、数据库、中间件MQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty等等**
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
Java基础、异常、集合、并发编程、JVM、Spring全家桶、MyBatis、Redis、数据库、中间件MQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty等等**
[外链图片转存中…(img-UGDMiKEj-1713627952075)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-cs5BIRuP-1713627952075)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!