עיבוד אסינכרוני ברקע
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
עבודה אסינכרונית היא הרכיב השני של עבודה ברקע, לצד עבודה מתמשכת. גם פעולות מתמשכות וגם פעולות אסינכרוניות מתבצעות ברקע, אבל בסופו של דבר הן שונות למדי.
עבודה אסינכרונית היא עבודה ש:
- מתרחש ברגע נתון.
- לא צריך לשמור את הנתונים אחרי הפעלה מחדש של האפליקציה או של המכשיר.
- מתרחש מחוץ ל-thread הראשי, או חוסם את ה-thread הראשי.
ההבדל הוא שבניגוד לעבודה מתמשכת, אפשר לתזמן עבודה זמנית לביצוע עתידי, והיא נשארת מתוזמנת גם אחרי הפעלה מחדש של האפליקציה או של המכשיר.
דוגמה לעבודה אסינכרונית היא שליחת בקשת HTTP מחוץ לשרשור הראשי, והחזרת התוצאה שלה רק כשהיא מגיעה.
Java ו-Kotlin
הדרך שבה מטפלים בעבודה אסינכרונית תלויה בארכיטקטורה הכוללת של האפליקציה שבה משתמשים. אם אתם עובדים עם אפליקציה בשפת התכנות Java, הצרכים שלכם שונים מאלה של מי שעובד עם Kotlin.
קריאה נוספת
מידע נוסף על עבודה מתמשכת זמין בסקירה הכללית על עבודה מתמשכת.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Asynchronous background processing\n\nAsynchronous work is the second component of background work, alongside\npersistent work. While both persistent and asynchronous work take place in the\nbackground, they are ultimately quite different.\n\nAsynchronous work is that which:\n\n- Takes place in the moment.\n- Does not need to persist across app restarts or device reboots.\n- Occurs off the main thread, or blocks the main thread.\n\nThis is in contrast to persistent work, which you may schedule for future\nexecution and which remains scheduled through app restarts and device reboots.\nAn example of asynchronous work may be sending an HTTP request off the main\nthread, returning its result only when it arrives.\n\nJava and Kotlin\n---------------\n\nThe way you handle asynchronous work depends on the overall app architecture\nyou follow. If you are working with a Java Programming Language app, your needs\nare different than if you are working with Kotlin.\n\n| | Kotlin | Java |\n| Solution | Coroutines. | Java threads. |\n| Further reading | For a full overview of Coroutines, see the [Coroutines guide](/kotlin/coroutines). | See the [Java Threads](/guide/background/asynchronous/java-threads) page for more information. |\n|-----------------|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|\n\nFurther reading\n---------------\n\nFor more information on persistent work, see the [persistent work overview](/guide/background/persistent)."]]