先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Python全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Python知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注Python)
正文
Thread.sleep(20);
thread.interrupt();
}
}
实际上线程并未停止,只是for循环终止,可以通过抛出异常来直接停止线程
public class MyThread extends Thread {
public void run(){
super.run();
try {
for(int i = 0;i < 50000;i++){
if(this.interrupted()){
throw new InterruptedException();
}
System.out.println(“i=”+i);
}
System.out.println(“end”);
}catch(InterruptedException e){
System.out.println(“线程已退出”);
}
}
public static void main(String[] args) throws InterruptedException{
MyThread thread = new MyThread();
thread.start();
Thread.sleep(20);
thread.interrupt();
}
}
线程的暂停:
1.suspend()和resume()方法(已作废)
public class MyThread extends Thread {
private long i = 0;
public long geti(){
return i;
}
public void seti(long i){
this.i = i;
}
public void run(){
while(true){
i++;
}
}
public static void main(String[] args){
try{
MyThread thread = new MyThread();
thread.start();
Thread.sleep(5000);
//第一段
thread.suspend();
System.out.println(“第一段=”+System.currentTimeMillis()+“i=”+thread.geti());
Thread.sleep(5000);
System.out.println(“第一段=”+System.currentTimeMillis()+“i=”+thread.geti());
//第二段
thread.resume();
Thread.sleep(5000);
//第三段
thread.suspend();
System.out.println(“第二段=”+System.currentTimeMillis()+“i=”+thread.geti());
Thread.sleep(5000);
System.out.println(“第二段=”+System.currentTimeMillis()+“i=”+thread.geti());
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
缺点
使用不当,会造成公共的同步对象的独占,使得其他线程无法访问公共同步对象
2.yield方法
放弃当前的cpu资源,让给其他任务,但放弃时间不确定,
Thread.yield()
线程的优先级
线程优先级决定了谁得到的cpu资源较多,也就是cpu优先执行优先级较高的线程对象中的任务
方法:setPriority(int priorrity)
读取错误
如下程序不是线程安全的
public class Mutable {
private int value;
public void setvalue(int value){
this.value = value;
}
public int getvalue(){
return value;
}
}
原因是如果某个线程调用了setvalue,那么另一个正在调用getvalue的线程可能会看到更新后的value值,也可能看不到,应该进行同步
public class Mutable {
private int value;
public synchronized void setvalue(int value){
this.value = value;
}
public synchronized int getvalue(){
return value;
}
}
重入:
当某个线程请求一个由其他线程持有的锁时,发出请求的线程就会阻塞,然而由于内置锁的可重入,如果某个线程师徒获德
一个已经由它持有的锁,那么这个请求就会成功,重入意味着获取锁的操作粒度是线程而非调用,入下面程序
public class Test1{
public synchronized void dosomething(){
}
}
class Test2 extends Test1{
public synchronized void dosomething(){
super.dosomething();
}
}
子类改写了父类的代码,然后调用父类的方法,此时如果如果没有可重入的锁,会产生死锁的问题,原因是Test1和Test2的
dosomething方法都是synchronized的,每个dosomething方法被调用时都会获取Test1上的锁,然而如果锁时不可以重入的,那么在
调用super.dosomething将无法获得Test1上的锁,因为该锁已经被持有,线程将永远停顿
当一个线程执行的代码出现异常时,锁自动释放
同步不具有继承性
synchronized同步代码块
用Synchronized修饰方法时,如果一个线程需要执行的时间过长,会造成等待时间过长
可以使用同步代码块解决弊端,如下
public class Task {
private String getData1;
private String getData2;
public void doLongTimeTask(){
try{
System.out.println(“task begin”);
Thread.sleep(3000);
String privateGetData1 = “长时间处理任务后远程返回的值1 threadname=”+Thread.currentThread().getName();
String privateGetData2 = “长时间处理任务后远程返回的值1 threadname=”+Thread.currentThread().getName();
synchronized(this){
getData1 = privateGetData1;
getData2 = privateGetData2;
}
System.out.println(getData1);
System.out.println(getData2);
System.out.println(“task end”);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
仅仅同步有可能造成线程不安全的部分
如果一个类中有很多sunchronized方法,可以使用非this对象的锁,这样不会造成阻塞,但是必须保证多个线程持有同一个对象的锁
静态同步synchronized方法需要用.class对象的锁
在使用String作为锁时要注意常量池缓存的问题
synchronized同步方法的无限等待问题
public class Test1 implements Runnable{
public synchronized void run(){
while(true){
System.out.println(Thread.currentThread().getName()+“在运行”);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args){
Test1 test = new Test1();
Thread task1 = new Thread(test);
Thread task2 = new Thread(test);
task1.start();
task2.start();
}
}
如上代码,一个线程进入到同步方法中,进入while循环,将会一直持有锁,别的方法无法进入,使用同步代码块的方式
public class Test1 implements Runnable{
public synchronized void run(){
while(true){
synchronized(this){
System.out.println(Thread.currentThread().getName()+“在运行”);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args){
Test1 test = new Test1();
Thread task1 = new Thread(test);
Thread task2 = new Thread(test);
task1.start();
task2.start();
}
}
多线程的死锁问题
不同线程都在等待不可能被释放的锁,导致所有任务都无法继续完成,如下列代码
public class DealThread implements Runnable{
public String username;
public Object lock1 = new Object();
public Object lock2 = new Object();
public void setflag(String username){
this.username = username;
}
@Override
public void run() {
// TODO Auto-generated method stub
if(username.equals(“a”)){
synchronized(lock1){
try{
System.out.println("username = "+username);
Thread.sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}
synchronized(lock2){
System.out.println(“lock1-lock2”);
}
}
}
if(username.equals(“b”)){
synchronized(lock2){
try{
System.out.println("username = "+username);
一、Python所有方向的学习路线
Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。
二、Python必备开发工具
工具都帮大家整理好了,安装就可直接上手!
三、最新Python学习笔记
当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。
四、Python视频合集
观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。
五、实战案例
纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
六、面试宝典
简历模板![在这里插入图片描述](https://img-blog.csdnimg.cn/646863996ac44da8af500c049bb72fbd.png#pic_center)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
c454a3e5b4439b8600b50011cc8fe4.png)
简历模板![在这里插入图片描述](https://img-blog.csdnimg.cn/646863996ac44da8af500c049bb72fbd.png#pic_center)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
[外链图片转存中…(img-Of4i59po-1713244462499)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!