31.HarmonyOS App(JAVA)鸿蒙系统app Service服务的用法

鸿蒙系统app Service服务的用法

后台任务调度和管控

  • HarmonyOS将应用的资源使用生命周期划分为前台、后台和挂起三个阶段。前台运行不受资源调度的约束,后台会根据应用业务的具体任务情况进行资源使用管理,在挂起状态时,会对应用的资源使用进行调度和控制约束,以保障其他体验类业务对资源的竞争使用。
  • 后台任务调度和管控主要对在后台状态下的资源使用进行控制,应用从前台退到后台,可能有各种业务诉求,为了达到系统资源使用能效最优的目的,HarmonyOS提供了后台任务能力。

后台任务类型

本文描述的后台任务特指应用或业务模块处于后台(无可见界面)时,有需要继续执行或者后续执行的业务。对这些应用不可见但要继续或者将要执行的业务动作,为避免后台任务调度和管控对业务执行的影响,HarmonyOS将后台任务分为三种类型:

  1. 无后台业务:退后台后,无任务需要处理。
  2. 短时任务:退后台后,如果有紧急不可推迟且短时间能完成的任务,如应用退后台要进行数据压缩,不可中断,则使用短时任务申请延迟进入挂起(Suspend)状态。
  3. 长驻任务:如果是用户发起的可感知业务需要长时间后台运行的,如后台播放音乐、导航、上传下载、设备连接、VoIP等,则使用长驻任务避免进入挂起(Suspend)状态。

短时任务

退到后台的应用有不可中断且短时间能完成的任务时,可以使用短时任务机制,该机制允许应用在后台短时间内完成任务,保障应用业务运行不受后台生命周期管理的影响。

  • 注意:短时任务仅针对应用的临时任务提供资源使用生命周期保障,限制单次最大使用时长为3分钟,全天使用配额默认为10分钟(具体时长系统根据应用场景和系统状态智能调整)。
  • 接口请参考:BackgroundTaskManager接口说明。

短时任务使用约束

短时任务的使用需要遵从如下约束和规则:

  • 申请时机:允许应用在前台时,或退后台在被挂起之前(应用退到后台默认有6~12秒的运行时长,具体时长由系统根据具体场景决定)申请延迟挂起,否则可能被挂起(Suspend),导致申请失败。
  • 超时:延迟挂起超时(Timeout),系统通过回调知会应用,应用需要取消对应的延迟挂起,或再次申请延迟挂起。超期不取消或不处理,该应用会被强制取消延迟挂起。
  • 取消时机:任务完成后申请方应用主动取消延时申请,不要等到超时后被系统取消,否则会影响该应用的后台允许运行时长配额。
  • 配额机制:为了防止应用滥用保活,或者申请后不取消,每个应用每天都会有一定配额(会根据用户的使用习惯动态调整),配额消耗完就不再允许申请短时任务,所以应用完成短时任务后立刻取消延时申请,避免消耗配额。(注,这个配额指的是申请的时长,系统默认应用在后台运行的时间不计算在内)。

长驻任务

长驻任务类型给用户能直观感知到的且需要一直在后台运行的业务提供后台运行生命周期的保障。比如,业务需要在后台播放声音,或者需要在后台持续导航定位等,此类用户可以感知到的后台业务行为,可以通过使用长驻任务对应的后台模式保障业务在后台的运行,支撑应用完成在后台的业务。

后台模式分类

HarmonyOS提供了十种后台模式,供需要在后台做长驻任务的业务使用,具体的后台模式类型如下:

长驻任务后台模式

英文名

描述

数据传输

data-transfer

通过网络/对端设备进行数据下载、备份、分享、传输等业务

播音

audio-playback

音频输出业务

录音

audio-recording

音频输入业务

画中画

picture-in-picture

画中画、小窗口播放视频业务

音视频通话

voip

音视频电话,VoIP业务

导航/位置更新

location

定位、导航业务

蓝牙设备连接及传输

bluetooth-interaction

蓝牙扫描、连接、传输业务

WLAN设备连接及传输

wifi-interaction

WLAN扫描、连接、传输业务

屏幕抓取

screen-fetch

录屏、截屏业务

多设备互联

multiDeviceConnection

多设备互联,分布式调度和迁移等业务

使用长驻任务

  1. HarmonyOS应用开发工具DevEco Studio在业务的ServiceAbility创建的时候提供了后台模式的选择,针对当前创建的ServiceAbility可以赋予对应的后台模式类型设置,如下图所示:

    业务根据需要选择对应的后台模式以后,会在应用的config.json文件中新创建的ServiceAbility组件下生成对应选择的后台模式配置,如下图所示:

    说明

    只有ServiceAbility才有对应的后台模式类型选择和配置。

  2. 在Service创建的方法里面调用keepBackgroundRunning(),将Service与通知绑定。

    调用keepBackgroundRunning()方法前需要在配置文件中声明ohos.permission.KEEP_BACKGROUND_RUNNING权限。

    完成对应的后台业务以后,在销毁服务的方法中调用cancelBackgroundRunning()方法,即可停止使用长驻任务。

    请参考:前台Service。

长驻任务使用约束

  1. 如果用户选择可感知业务(如播音、导航、上传下载等),触发对应后台模式,在任务启动时或退入后台时,需要提醒用户。
  2. 如果任务结束,应用应主动退出后台模式。若在后台运行期间,系统监测到应用并未使用对应后台模式的资源,则会被挂起(Suspend)。
  3. 避免不合理地申请后台长驻任务,长驻任务类型要与应用的类型匹配,如任务类型与应用类型匹配表所示,如果执行的任务和申请的类型不匹配,也会被系统检测到并被挂起(Suspend)。
  4. 长驻任务是为了真正在后台长时间执行某任务,如果一个应用申请了长驻任务,但在实际运行过程中,并未真正运行或执行此类任务时,也会被系统检测到并被挂起(Suspend)。

托管任务

托管任务是系统提供的一种后台代理机制。通过系统提供的代理API接口,用户可以把任务(如后台下载、定时提醒、后台非持续定位)交由系统托管。

托管任务类型

  1. 托管任务-后台非持续定位(non-sustained Location):如果应用未申请location常驻模式,且在后台依然尝试获取位置信息,此时应用行为被视为使用非持续定位能力,后台非持续定位限制每30分钟提供一次位置信息。应用不需要高频次定位时,建议优先使用非持续定位。
  2. 托管任务-后台提醒代理(Reminder):后台提醒代理主要提供了一种机制,使开发者在应用开发时,可以调用这些接口去创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。请参考:Reminder接口使用说明。
  3. 托管任务-后台下载代理:系统提供DownloadSession接口实现下载任务代理功能,应用提交下载任务后,应用被退出,下载任务仍然可以继续执行,且支持下载任务断点续传。请参考:DownloadSession接口使用说明。

托管任务使用约束

  1. 后台下载代理,系统会根据用户场景和设备状态,对不同的下载任务进行相应的管控,避免影响功耗和性能。
  2. 后台非持续定位和后台提醒代理需要申请对应的权限。后台提醒需要申请ohos.permission.PUBLISH_AGENT_REMINDER权限,后台非持续定位需要申请ohos.permission.LOCATION和ohos.permission.LOCATION_IN_BACKGROUND权限。
  3. 资源滥用会影响系统性能和功耗,托管任务类型要与应用类型匹配
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">

    <Button
        ohos:id="$+id:btn_start"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#A306F52E"
        ohos:layout_alignment="horizontal_center"
        ohos:text="启动服务"
        ohos:text_size="40vp"
        />
    <Button
        ohos:id="$+id:btn_stop"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#A3235DEE"
        ohos:layout_alignment="horizontal_center"
        ohos:text="停止服务"
        ohos:text_size="40vp"
        />
    <Button
        ohos:id="$+id:btn_connect"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#A306F52E"
        ohos:layout_alignment="horizontal_center"
        ohos:text="连接服务"
        ohos:text_size="40vp"
        />
    <Button
        ohos:id="$+id:btn_disconnect"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#A3235DEE"
        ohos:layout_alignment="horizontal_center"
        ohos:text="断开连接服务"
        ohos:text_size="40vp"
        />
    <Button
        ohos:id="$+id:btn_foreground"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#A306F52E"
        ohos:layout_alignment="horizontal_center"
        ohos:text="启动前台service"
        ohos:text_size="40vp"
        />
    <Button
        ohos:id="$+id:btn_foreground_stop"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#A3235DEE"
        ohos:layout_alignment="horizontal_center"
        ohos:text="停止后台服务"
        ohos:text_size="40vp"
        />
    <TextField
        ohos:id="$+id:text_filed_info"
        ohos:height="300vp"
        ohos:background_element="#FC0A84EF"
        ohos:text="信息显示区域"
        ohos:width="350vp"
        ohos:hint=""
        ohos:margin="2vp"
        ohos:text_size="20vp"/>
    <Clock
        ohos:id="$+id:clock"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="#FF80EF66"
        ohos:layout_alignment="left"

        ohos:text_size="20vp"
        />



</DirectionalLayout>

创建服务类 

 

package com.example.serviceability;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.event.notification.NotificationRequest;
import ohos.rpc.IRemoteObject;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class ForegroundServiceAbility extends Ability {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "Demo");

    @Override
    public void onStart(Intent intent) {
        HiLog.error(LABEL_LOG, "ForegroundServiceAbility::onStart");
        NotificationRequest.NotificationNormalContent content3 = new NotificationRequest.NotificationNormalContent()
                .setTitle("测试hap应用")
                .setText("该service将会常留后台");
        NotificationRequest.NotificationContent notificationContent = new NotificationRequest.NotificationContent(content3);
        NotificationRequest request3 = new NotificationRequest(1001).setContent(notificationContent);
        keepBackgroundRunning(1001,request3);
        super.onStart(intent);

    }

    @Override
    public void onBackground() {
        super.onBackground();
        HiLog.info(LABEL_LOG, "ForegroundServiceAbility::onBackground");
    }

    @Override
    public void onStop() {
        super.onStop();
        HiLog.info(LABEL_LOG, "ForegroundServiceAbility::onStop");
    }

    @Override
    public void onCommand(Intent intent, boolean restart, int startId) {
    }

    @Override
    public IRemoteObject onConnect(Intent intent) {
        return null;
    }

    @Override
    public void onDisconnect(Intent intent) {
    }
}

 

 

package com.example.serviceability;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.LocalRemoteObject;
import ohos.aafwk.content.Intent;
import ohos.rpc.IRemoteObject;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class ServiceAbility extends Ability {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "Demo");

    @Override
    public void onStart(Intent intent) {
        HiLog.error(LABEL_LOG, "ServiceAbility::onStart");
        super.onStart(intent);


    }

    @Override
    public void onBackground() {
        super.onBackground();
        HiLog.info(LABEL_LOG, "ServiceAbility::onBackground");
    }

    @Override
    public void onStop() {
        super.onStop();
        HiLog.info(LABEL_LOG, "ServiceAbility::onStop");
    }

    @Override
    public void onCommand(Intent intent, boolean restart, int startId) {
    }

    @Override
    public IRemoteObject onConnect(Intent intent) {
        HiLog.info(LABEL_LOG,"OnConnect");
        return new MyRemoteObject();

    }

    @Override
    public void onDisconnect(Intent intent) {
        HiLog.info(LABEL_LOG,"断开服务");
    }
    public class MyRemoteObject extends LocalRemoteObject
    {
       public MyRemoteObject()
       {
           HiLog.info(LABEL_LOG,"my remoteobject被创建");
       }
       //自定义方法,控制service的
       public String manipulateService()
       {
           HiLog.info(LABEL_LOG,"自定义方法,控制service的");
           return "exec_value666";
       }
    }

}

package com.example.serviceability.slice;

import com.example.serviceability.ForegroundServiceAbility;
import com.example.serviceability.ResourceTable;
import com.example.serviceability.ServiceAbility;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.IAbilityConnection;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Clock;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.bundle.ElementName;
import ohos.rpc.IRemoteObject;

public class MainAbilitySlice extends AbilitySlice {
    TextField textField;
    Clock clock2;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        textField  = (TextField) findComponentById(ResourceTable.Id_text_filed_info);
        clock2 = (Clock) findComponentById(ResourceTable.Id_clock);
        clock2.setFormatIn24HourMode("yyyy-MM-dd HH:mm:ss");



        Button btn_start =(Button) findComponentById(ResourceTable.Id_btn_start);
        Button btn_stop =(Button) findComponentById(ResourceTable.Id_btn_stop);
        Button btn_con =(Button) findComponentById(ResourceTable.Id_btn_connect);
        Button btn_discon =(Button) findComponentById(ResourceTable.Id_btn_disconnect);
        Button btn_foreground = (Button) findComponentById(ResourceTable.Id_btn_foreground);
        Button btn_foreground_stop = (Button) findComponentById(ResourceTable.Id_btn_foreground_stop);
        btn_foreground_stop.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                StopForegoundService();
                textField.append(clock2.getText()+"已停止后台服务\n");
            }
        });
        btn_foreground.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                StartForegoundService();
                textField.append(clock2.getText()+"启动后台服务\n");
            }
        });
        btn_start.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                StartService();
            }
        });
        btn_stop.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                StopService();
            }
        });
        btn_con.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                ConnectService();
            }
        });
        btn_discon.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                disconnectAbility(connection3);
                textField.append(clock2.getText()+"已断开服务\n");
            }
        });

    }
    public void StartService()
    {
        Intent intent1 = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.serviceability")
                .withAbilityName("com.example.serviceability.serviceability")
                .build();
        intent1.setOperation(operation);
        startAbility(intent1);
    }
    public void StopService()
    {
        Intent intent1 = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.serviceability")
                .withAbilityName("com.example.serviceability.serviceability")
                .build();
        intent1.setOperation(operation);
        stopAbility(intent1);
    }
    //连接服务
    public void ConnectService()
    {
        Intent intent1 = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.serviceability")
                .withAbilityName("com.example.serviceability.ServiceAbility")
                .build();
        intent1.setOperation(operation);
        connectAbility(intent1,connection3);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
    //连接远程的Service的IAbilityConnection对象
    private IAbilityConnection connection3 = new IAbilityConnection() {
        //通过远程对象操纵Service
        @Override
        public void onAbilityConnectDone(ElementName elementName, IRemoteObject iRemoteObject, int i) {
            ServiceAbility.MyRemoteObject object3 = (ServiceAbility.MyRemoteObject) iRemoteObject;
            String aa = object3.manipulateService();
            textField.append(clock2.getText()+" 服务信息:"+aa);
        }

        @Override
        public void onAbilityDisconnectDone(ElementName elementName, int i) {

        }
    };
    public void StartForegoundService()
    {
        Intent intent1 = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.serviceability")
                .withAbilityName(ForegroundServiceAbility.class.getName())
                .build();
        intent1.setOperation(operation);
        startAbility(intent1);
    }
    public void StopForegoundService()
    {
        Intent intent1 = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.serviceability")
                .withAbilityName(ForegroundServiceAbility.class.getName())
                .build();
        intent1.setOperation(operation);
        stopAbility(intent1);
    }
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/472733.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

《C语言深度剖析》---------关键字(1)

1.双击实质--->加载内存 windows系统里面&#xff0c;双击的本质就是运行程序&#xff0c;把程序加载到内存里面&#xff1b; 任何程序运行的时候都必须加载到内存里面&#xff1b; 程序没有运行之前在硬盘里面&#xff0c;为什么程序运行之前必须加载到内存里面呢&#…

Spring Web MVC入门(5)

响应 在我们前面的代码例子中, 都已经设置了响应数据Http响应结果可以是数据, 也可以是静态页面, 也可以针对响应设置状态码, Header信息等. 返回静态页面 创建前端页面index.html(注意路径) html代码如下: <!DOCTYPE html> <html lang"en"> <hea…

Nutanix 国产化替代|一文了解 SmartX 超融合替代可行性与迁移方案

2022 年 8 月 19 日&#xff0c;Nutanix&#xff08;路坦力&#xff09;宣布中国市场自 2023 财年起将转型为合作伙伴销售主导模式&#xff0c;引起了广泛关注&#xff1b;同时结合当前 IT 基础架构的国产化趋势背景&#xff0c;不少正在使用和考虑使用 Nutanix 产品的企业开始…

Vue 中预加载组件

在 Vue 中&#xff0c;利用 VueRouter 可以轻松的实现两个组件&#xff08;页面&#xff09;之间的切换&#xff0c;有个常用的设计就是需要在登录页登录后跳转至一个内容页&#xff0c;通常的做法是在登录校验完成之后立即切换路由至内容页&#xff0c;接着内容页发送网络请求…

极简生活|2024年让自己越来越好的18个极简好习惯

哈喽&#xff0c;你好啊&#xff0c;我是雷工&#xff01; 转眼间已经进入了2024年&#xff0c;新的一年&#xff0c;新的开始。 俗话说&#xff1a;百尺高台起于垒土&#xff0c;千里之堤毁于蚁穴。 好习惯积累的越多&#xff0c;坏习惯越来越少&#xff0c;我们的生活才能越…

Iterator对象功能学习

package config;import java.util.Iterator; import java.util.Properties; import java.util.Set;/*** 这个类演示了如何使用Properties类来存储和访问键值对。* Properties类继承自Hashtable&#xff0c;因此它可以用来存储键值对数据&#xff0c;且支持同步。*/ public clas…

MySQL介绍

一、MySQL数据库介绍 1、发展史 1996年 MySQL1.0 2008年1月16日 Sun公司收购了 MySQL 2009年4月20日 Oracle收购了Sun公司 MySQL是一种开放源代码的关系型数据库管理系统 使用最常用的数据库管理语言 SQL&#xff08;结构化查询语言&#xff09; MySQL是开放源代码的 因此所有…

基于Springboot的员工健康管理系统(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的员工健康管理系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系结构…

【c++】c++基本语法知识-命名空间-输入输出-缺省参数

主页&#xff1a;醋溜马桶圈-CSDN博客 专栏&#xff1a;c_醋溜马桶圈的博客-CSDN博客 gitee&#xff1a;mnxcc (mnxcc) - Gitee.com 目录 1.命名空间 1.2 命名空间定义 1.3 命名空间使用 命名空间的三种使用方式 2.C输入&输出 std命名空间的使用惯例 3.缺省参数 3…

Win11初始化系统遇一文解决

这个是目录 一、设置内的初始化无法使用时&#xff0c;使用以下工具二、将桌面移动到D盘三、解决win11桌面右键创建只有一个带盾牌的文件夹问题四、win11 系统停止更新五、office安装1、使用的是 Office Tool plus2、使用WPS 六、D盘有感叹号七、打开组策略编辑器(gpedit.msc)失…

【Docker】-- 如何安装docker

一、安装docker 首先要安装一个yum工具 yum install -y yum-utils 安装成功后&#xff0c;执行命令&#xff0c;配置Docker的yum源&#xff1a; yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 最后&#xff0c;执行命令&#x…

Windows 安装 Graalvm 环境(JDK 22)

Windows 安装 Graalvm 环境 系统&#xff1a;Windows 11 官方参考指南&#xff1a;https://www.graalvm.org/jdk22/docs/getting-started/windows/ 安装 Graalvm & 下载 native-image 下载 Graalvm 并安装 下载的 SDK 选择最新版&#xff08;JDK 22&#xff09;&#xff…

UE4_官方动画内容示例1.3_ 运动混合空间(Locomotion BlendSpace)

如何使用运动&#xff08;Locomotion&#xff09;混合空间将Actor在不同方向上及不同速度的运动混合起来。&#xff08;例如&#xff0c;展示了一个混合了以不同速度向后、前、左和右走路/跑步动作的Actor&#xff09;。 一、相关知识点&#xff1a; 混合空间是允许根据多个输…

《汽车数据安全若干问题合规实践指南》正式发布(百度盘下载)

指南针对汽车数据安全的重要合规内容&#xff0c;结合汽车行业特有场景&#xff0c;参考行业最佳实践&#xff0c;提出合规实践建议。指南旨在进一步提高汽车行业数据安全保护水平&#xff0c;增强汽车企业数据安全合规保障能力&#xff0c;推动汽车数据价值安全使用&#xff0…

初始Java篇(JavaSE基础语法)(2)

个人主页&#xff08;找往期文章包括但不限于本期文章中不懂的知识点&#xff09;&#xff1a;我要学编程(ಥ_ಥ)-CSDN博客 目录 逻辑控制 顺序结构 分支结构 if语句 switch 语句 循环结构 while 循环 for 循环 do while 循环 输入输出 输出到控制台 从键盘输入 …

AIGC——ComfyUI工作流搭建、导入与常用工作流下载

工作流 ComfyUI工作流是一个基于图形节点编辑器的工作流程&#xff0c;通过拖拽各种节点到画布上&#xff0c;连接节点之间的关系&#xff0c;构建从加载模型到生成图像的流程。每个节点代表一个与Stable Diffusion相关的模型或功能&#xff0c;节点之间通过连线传递图片信息。…

蓝桥杯-数的潜能-求快速幂

题目 思路 --将数字拆分成加和的形式&#xff0c;并且相乘。数据范围到10的18次方&#xff0c;暴力肯定不行&#xff0c;要找规律。拆分成1肯定不行&#xff0c;对乘法没有贡献&#xff0c;2可以&#xff0c;3也可以&#xff0c;4、5、6等大于3的数字都可以用2和3来表示。所以…

【堆】Top-K问题

标题&#xff1a;C语言库函数scanf&#xff08;&#xff09;解读 水墨不写bug &#xff08;图片来源于网络&#xff09; 正文开始&#xff1a; Top-K问题是一类问题的统称&#xff1a; 即根据对象的某一属性&#xff0c;找出这个属性最突出的K个对象&#xff0c;并且通常对象…

简单了解多线程

并发和并行 并发&#xff1a; 在同一时刻&#xff0c;多个指令在单一CPU上交替指向 并行&#xff1a;在同一时刻&#xff0c;多个指令在多个CPU上同时执行 2核4线程&#xff0c;4核8线程&#xff0c;8核16线程&#xff0c;16核32线程 基础实现线程的方式 Thread :继承类 &…