
سلام.️
حالتون چطوره؟?
بعد یه هفته غیبت برگشتم.
توی این قسمت در مورد مفهوم برنامه نویسی چند نخی حرف میزنیم. یه مثال میزنیم (سرعت اجرا یه برنامه رو دو برابر میکنیم) و میگم که کجا ها و چجوری میتونید ازش استفاده کنید.
ویدیو رو میتونید از لینک های زیر ببینید:
youtube: https://youtu.be/Y3XIkbyrr84
aparat: https://aparat.com/v/eRYTN
اینم کدی که توی این قسمت نوشته شد:
import java.util.Date; public class ThreadTest{ static boolean checkPrime(int n) { int i, m = 0, flag = 0; m = n / 2; if (n == 0 || n == 1) { return false; } else { for (i = 2; i <= m; i++) { if (n % i == 0) { return false; } } if (flag == 0) { return true; } } // end of else return false; } static void countPrimes(){ int count = 0; for(int i=0 ; i<1000000 ; i++){ if(checkPrime(i)){ count++; } } System.out.println(count); } static int count = 0; static boolean isFirstDone=false; static void countPrimesMT(){ new Thread(new Runnable(){ @Override public void run() { for (int i = 0; i < 700000; i++) { if (checkPrime(i)) { count++; } } if(!isFirstDone){ isFirstDone=true; }else{ System.out.println(count); } } }).start(); for (int i = 700000; i < 1000000; i++) { if (checkPrime(i)) { count++; } } if (!isFirstDone) { isFirstDone = true; } else { System.out.println(count); } } public static void main(String[] args) { long startTime = new Date().getTime(); countPrimes(); long endTime = new Date().getTime(); System.out.println(endTime-startTime); startTime = new Date().getTime(); countPrimesMT(); endTime = new Date().getTime(); System.out.println(endTime-startTime); } }
اینم که همچنان گروه تلگراممونه:
https://t.me/intern_plus_plus_group
اینم که لینک گیت هاب ماس که کد هایی که مینویسم رو میزارم:
https://github.com/intern-plus-plus/
باعث خوشحالی من میشه اگه این ویدیو رو به کسایی که فکر میکنید به دردشون میخوره بفرستید.
website: internplusplus.ir
telegram: @intern_plus_plus
#سفر_به_اعماق_کامپیوتر