首页 > 其他分享 >记事本

记事本

时间:2024-02-21 17:44:19浏览次数:14  
标签:code return name default 线程 fallback 记事本

1. 编程

1.1 Java

1.1.1 线程池

线程池 7大配置

    /**
     * Creates a new {@code ThreadPoolExecutor} with the given initial
     * parameters.
     *
     * @param corePoolSize the number of threads to keep in the pool, even
     *        if they are idle, unless {@code allowCoreThreadTimeOut} is set
     * @param maximumPoolSize the maximum number of threads to allow in the
     *        pool
     * @param keepAliveTime when the number of threads is greater than
     *        the core, this is the maximum time that excess idle threads
     *        will wait for new tasks before terminating.
     * @param unit the time unit for the {@code keepAliveTime} argument
     * @param workQueue the queue to use for holding tasks before they are
     *        executed.  This queue will hold only the {@code Runnable}
     *        tasks submitted by the {@code execute} method.
     * @param threadFactory the factory to use when the executor
     *        creates a new thread
     * @param handler the handler to use when execution is blocked
     *        because the thread bounds and queue capacities are reached
     * @throws IllegalArgumentException if one of the following holds:<br>
     *         {@code corePoolSize < 0}<br>
     *         {@code keepAliveTime < 0}<br>
     *         {@code maximumPoolSize <= 0}<br>
     *         {@code maximumPoolSize < corePoolSize}
     * @throws NullPointerException if {@code workQueue}
     *         or {@code threadFactory} or {@code handler} is null
     */
    public ThreadPoolExecutor(int corePoolSize,
                              int maximumPoolSize,
                              long keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue<Runnable> workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler){

                              }
  1. corePoolSise: 要保留在池中的线程数,即使它们处于空闲状态,除非 allowCoreThreadTimeOut 已设置
  2. maximumPoolSize 池中允许的最大线程数
  3. keepAliveTime 当线程数大于核心数时,这是多余的空闲线程在终止之前等待新任务的最长时间。
  4. unit 参数的时间 keepAliveTime 单位
  5. workQueue 用于在执行任务之前保留任务的队列。此队列将仅 Runnable 保存该方法提交 execute 的任务
  6. threadFactory 执行器创建新线程时使用的工厂
  7. handler 由于达到线程边界和队列容量而被阻止执行时要使用的处理程序

线程池执行的流程

  1. 线程池创建,准备好core数量的核心,准备接受任务
  2. 新的任务进来,用core准备好的空闲线程执行
    1)core满了,就将再进来的任务放入到阻塞队列中,空闲的core就会自己去阻塞队列获取任务并执行
    2)阻塞队列满了,就直接开新线程执行,最大只能开到指定的数量
    3)max 都执行好了 max-core数量空闲的线程会在keepAliveTime指定的时间后自动销毁。最终保持到core大小
    3)如果线程数开到了max的数量,还有新任务进来,就会使用reject指定的拒绝策略进行处理
  3. 所有线程穿件都是由指定的factory创建的

常见的线程池

  • newCachedThreadPool: 创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则创建线程
  • newFixedThreadPool: 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待
  • newScheduledThreadPool: 创建一个定长线程池,支持定时及周期性任务执行
  • newSingleThreadExecutor: 创建一个单线程的线程池

1.1.2 CompletableFuture

  1. 创建异步对象
    CompletableFuture 提供了四个静态方法来创建一个异步操作
public static CompletableFuture<Void> runAsync(Runnable runnable)
public static CompletableFuture<Void> runAsync(Runnable runnable,
                                                   Executor executor)
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) 
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier,
                                                       Executor executor)                                                   

备注

  • runXxx是没有返回结果的,supply都是可以获取返回结果的
  • 可以传入自定义的线程池,否则就用默认的线程池

1.1.3 实际应用

将List分片处理
img

2. 分布式

2.1 Spring Cloud Alibaba以及feignClient

@FeignCliet

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FeignClient {

	/**
	 * The name of the service with optional protocol prefix. Synonym for {@link #name()
	 * name}. A name must be specified for all clients, whether or not a url is provided.
	 * Can be specified as property key, eg: ${propertyKey}.
	 * @return the name of the service with optional protocol prefix
	 */
	@AliasFor("name")
	String value() default "";

	/**
	 * The service id with optional protocol prefix. Synonym for {@link #value() value}.
	 * @deprecated use {@link #name() name} instead
	 * @return the service id with optional protocol prefix
	 */
	@Deprecated
	String serviceId() default "";

	/**
	 * This will be used as the bean name instead of name if present, but will not be used
	 * as a service id.
	 * @return bean name instead of name if present
	 */
	String contextId() default "";

	/**
	 * @return The service id with optional protocol prefix. Synonym for {@link #value()
	 * value}.
	 */
	@AliasFor("value")
	String name() default "";

	/**
	 * @return the <code>@Qualifier</code> value for the feign client.
	 */
	String qualifier() default "";

	/**
	 * @return an absolute URL or resolvable hostname (the protocol is optional).
	 */
	String url() default "";

	/**
	 * @return whether 404s should be decoded instead of throwing FeignExceptions
	 */
	boolean decode404() default false;

	/**
	 * A custom <code>@Configuration</code> for the feign client. Can contain override
	 * <code>@Bean</code> definition for the pieces that make up the client, for instance
	 * {@link feign.codec.Decoder}, {@link feign.codec.Encoder}, {@link feign.Contract}.
	 *
	 * @see FeignClientsConfiguration for the defaults
	 * @return list of configurations for feign client
	 */
	Class<?>[] configuration() default {};

	/**
	 * Fallback class for the specified Feign client interface. The fallback class must
	 * implement the interface annotated by this annotation and be a valid spring bean.
	 * @return fallback class for the specified Feign client interface
	 */
	Class<?> fallback() default void.class;

	/**
	 * Define a fallback factory for the specified Feign client interface. The fallback
	 * factory must produce instances of fallback classes that implement the interface
	 * annotated by {@link FeignClient}. The fallback factory must be a valid spring bean.
	 *
	 * @see feign.hystrix.FallbackFactory for details.
	 * @return fallback factory for the specified Feign client interface
	 */
	Class<?> fallbackFactory() default void.class;

	/**
	 * @return path prefix to be used by all method-level mappings. Can be used with or
	 * without <code>@RibbonClient</code>.
	 */
	String path() default "";

	/**
	 * @return whether to mark the feign proxy as a primary bean. Defaults to true.
	 */
	boolean primary() default true;

}

其中path、contextId、name、value是常见的配置项
path: 目的服务的context-path
context-Id 唯一性标识,当name一样 比如全部指向网关的时候 指定context-id feiClient才不会冲突
name: 目的服务,可以直接指向网关
使用FeignClient加上Spring Cloud Gateway的方式,相当于是外部请求走网关,内部请求直接走向服务本身

2.2 社交登录流程(以微博登录举例)

  1. 申请web社交登录api
  2. 填写重定向url

标签:code,return,name,default,线程,fallback,记事本
From: https://www.cnblogs.com/cxpress/p/18025855

相关文章

  • 家庭记事本(五)
    实现修改消费账单想要修改消费账单,也需要获取全部消费账单,这里不再复述,具体在前一页。修改步骤:1.超链接地址action表示请求的方法名,id表示那一条记录 2.获取该条信息依次调用Service,Dao层,通过id查询该条消费记录封装到对象中    3.接受返回信息  cost_edit页......
  • 家庭记事本(六)
    实现查询消费账单1.输入框  2.运用javascript,点击查询,提交输入框内关键字到Servlet  3.Web层接受请求参数action=query,关键词keyword,调用Service的query方法  4.Service层调用Dao层的query方法  5.Dao层通过具体的sql语句查询数据库并逐层返回结果到前端页面......
  • 你还在用系统自带的记事本吗?
    你还在用系统自带的记事本吗?前言每当我们要复制一段话、一篇文章,想要临时找个地方存放,我们第一选择是不是想要打开记事本粘贴一下,如果只是一些单纯文字,这个操作可以接受,但是如果你复制的是其他格式文字(sql、java、md等),那么系统自带的记事本粘贴出来的结果就有点想骂娘了。当然......
  • 电脑端网络记事本哪个安全稳定?
    随着互联网科技的飞速发展,越来越多的上班族发现在电脑上使用网络记事本的重要性。这种网络记事本不仅便于记录工作内容,而且自动将数据上传到云端进行备份,让用户不再为数据丢失而担忧。让我们来看看上班族使用网络记事本的好处。在日常工作中,我们需要记录会议纪要、项目进度、工作......
  • 电脑记事本在哪里打开?
    电脑是我们工作和生活中不可或缺的工具,而记事本软件作为记录工作、生活琐事的重要工具,在日常中发挥着关键作用。在工作中,需要及时记录会议安排、工作任务、注意事项等,这时候记事本软件可以帮助我们清晰地记录每个任务的截止日期、工作内容和重要会议时间,确保工作有条不紊地进行。......
  • notepad 记事本 - 大三下安卓课程设计+源代码+文档说明
    项目介绍基本功能:1.添加时间戳2.搜索功能附加功能:1.UI美化:设置背景颜色、设置字体颜色及大小2.导出笔记3.设置闹钟提醒4.分享笔记以下是实现功能的核心代码及解释:界面预览项目备注1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!2、本项目适合计算机相......
  • 2023安卓期末大作业-记事本app(可以登录,含完整源码+程序设计报告+运行视频+apk导出文件
    2023安卓期末大作业-记事本app(可以登录,含完整源码+程序设计报告+运行视频+apk导出文件)打包文件如下图所示:基于Android系统的简单记事本,它能够便携记录生活和工作的诸多事情,从而帮助人们有条理的进行时间管理。一个记事本,能够输入标题和内容,创建日期、最新修改日期等信息。如果没......
  • 《2023安卓期末大作业-记事本app(可以登录,含完整源码+程序设计报告+运行视频+apk导出文
    2023安卓期末大作业-记事本app(可以登录,含完整源码+程序设计报告+运行视频+apk导出文件)打包文件如下图所示:基于Android系统的简单记事本,它能够便携记录生活和工作的诸多事情,从而帮助人们有条理的进行时间管理。一个记事本,能够输入标题和内容,创建日期、最新修改日期等信息。如果没......
  • 自由撰稿人如何快速记录灵感?随手记录灵感素材的电子记事本
    随着互联网的发展,催生了很多新的职业,其中“自由撰稿人”就是很多年轻人正在做的工作。而对于自由撰稿人来说,灵感是创作的源泉。然而,灵感往往稍纵即逝,如何快速记录下来,成为了我们面临的一大挑战。那么自由撰稿人如何快速记录灵感呢?其实想要快速记录灵感,我们可以在手机上使用一款便......
  • 近40年后!微软记事本获“史诗级”更新:终于有字符计数功能
    近日,微软发布了面向Dev和Canary频道的Windows11更新,此次更新最大的亮点,就是为自带的记事本应用程序新增了字符计数功能。自1985年发布的Windows1.0开始,每一个版本的Windows系统都自带了记事本软件,可以用来快速编辑一些文本。而此前如果想要知道一个文本文档究竟有多少字,只能通......