static

每隔一段时间自动执行一次某个方法

我是研究僧i 提交于 2020-01-14 01:02:46
class Program { public static bool bStop = false; static int x = 10; static void Main(string[] args) { //定义线程 Thread LogThread = new Thread(new ThreadStart(DoService)); //设置线程为后台线程,那样进程里就不会有未关闭的程序了 LogThread.IsBackground = true; if (bStop == false) { LogThread.Start();//起线程 } Console.ReadKey(); } private static void DoService() { while (true) { bStop = false; SendToService(); System.Threading.Thread.Sleep(1000);//1000=1秒 } } private static void SendToService() { x++; Console.WriteLine(x); } } 来源: https://www.cnblogs.com/zhujie-com/p/12190086.html

20191230-Java内部类

旧巷老猫 提交于 2020-01-14 00:27:03
内部类 可以将一个类的定义放在里另一个类的内部 (所谓的内部类的概念只是出现在编译阶段,对于jvm层是没有内部类这个概念的) 内部类是可以访问外部类的私有字段和私有方法的 用处: 类的单继承问题,外部类不能再继承的类可以交给内部类继承 可以通过定义内部类来实现一个类私属于一个类,实现更好的封装性 代码优化:它需要更少的代码 分类: 静态内部类 非静态内部类(成员内部类、方法内部类、匿名内部类) 静态内部类 静态内部类的定义和普通的静态变量或者静态方法的定义方法是一样的:使用 static关键字 只有静态内部类才能允许使用static关键字修饰class 当内部类拥有和外部类同名的成员变量或者方法时,会发生隐藏现象,即默认情况下访问的是内部类的成员。 不能使用外部类的非static成员变量或者方法 定义一个静态内部类: public class StaticClassTest { private static String name ; private int age ; public static class In { // private int age; public void sayHello ( ) { //--编译报错-- //外部类的非静态私有字段age在静态内部类中是不允许访问 //System.out.println("hello "+age); System .

Django中的文件操作

白昼怎懂夜的黑 提交于 2020-01-13 20:54:36
一、静态文件的加载 1、使用步骤 ①、在工程目录下创建static目录,创建css/js/images等目录,并添加相关资源 ②、在settings.py中配置STATICFILES_DIRS STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ] ③、在模板中调用   绝对路径: <link rel="stylesheet" href="/static/css/my.css">   相对路径: {% load static %} 或 {% load staticfiles %} <img src="{% static 'images/bige.jpg' %}"> 2、重要配置 ①、STATIC_URL 静态资源的虚拟路径,会启动“静态资源探测器” ②、STATICFILES_DIRS “静态资源探测器”会首先去查找STATICFILES_DIRS配置里设置的目录下的静态资源;然后会去查找每个app下的static子目录下的静态资源 ③、STATIC_ROOT 可以通过"python manage.py collectstatic"命令将所有应用的静态资源收集到STATIC_ROOT指向的目录中 二、文件上传 本质上就是文件的读写操作,从一个文件读取,到另外一个文件写入。 上传文件所在的表单必须设置enctype=

Accessing class constants from instance stored in another class

匆匆过客 提交于 2020-01-13 20:34:06
问题 I have a class defined which has several constants defined through `const FIRST = 'something'; I have instantiated the class as $class = new MyClass() then I have another class that takes a MyClass instance as one of it's constructors parameters and stores it as $this->model = $myClassInstance; This works fine. But I am wondering how I can access the constants from that instance? I tried case $this->model::STATE_PROCESSING but my IDE tells me Incorrect access to static class member. and PHP

Template on address of variable with static storage

有些话、适合烂在心里 提交于 2020-01-13 19:30:11
问题 Does C++ allow templates to take the address of a variable with static storage as a parameter? Since a memory address is integral and those with static storage are known at compile time it seems possible. I found this question showing that this works for int*. Is it legal C++ to pass the address of a static const int with no definition to a template? So far, I haven't convinced my compiler accept pointers to other types like char*. Can templates be specialized on static addresses in general?

【java】static关键字

二次信任 提交于 2020-01-13 19:01:43
1.static关键字 1.1静态变量 传统属性所具备的特征:保存在内存中,且每个对象独享属性。 在定义一个类时,只是在描述某类事物的特征和行为,并没有产生具体的数据。只有通过new关键字创建该类的实例化对象后,系统才会为每个对象分配空间,存储各自的数据。有时候,我们希望某些特定的数据在内存中只有一份,而且能够被一个类的所有实例对象所共享。例如某个学院所有学生贡献同一个学生名称,此时安全不必在每个学生对象所占用的空间中都定义一个变量来表示学生名称,而可以在对象以外的空间定义一个表示学校名称的变量让所有对象来共享。 在一个java类中,可以使用是static关键字来修饰成员变量,该变量被称作静态变量。静态变量被所有实例共享,可以使用“类名.变量名”的形式来访问。static属性又称为类属性,保存在全局数据的内存之中,所以对象都可以进行数据区的访问。 class Student{ static String schoolName; } public class Test { public static void main(String[] args) { Student stu1=new Student(); Student.schoolName="学校"; System.out.println(stu1.schoolName); System.out.println(Student

JAVA经典算法之求素数

帅比萌擦擦* 提交于 2020-01-13 16:51:14
什么是素数 质数(素数)是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数。 计算原理: 在一个大于1的数a和它的2倍之间(即区间(a, 2a]中)必存在至少一个素数。 java代码 : package com . skindow . algorithm . calculationPrimeNumber ; /** * @ Description :求n ~ m数之间素数得个数,并输出这些素数 * @ Author : skindow * @ CreateDate : 2020/1/13$ 14:49$ */ public class CalculationPrimeNumber { private static final Integer START_NUM = 100 ; private static final Integer END_NUM = 200 ; private static Integer PRIME_NUM = 0 ; public static void main ( String [ ] args ) { for ( int i = START_NUM ; i < END_NUM ; i ++ ) { if ( isPrime ( ( double ) i ) ) { System . out . print ( i + "," ) ;

在vue中动态加载图片src属性,会出现图片加载不出来的情况

核能气质少年 提交于 2020-01-13 13:13:34
先说明下vue-cli的assets和static的两个文件的区别,因为这对你理解后面的解决办法会有所帮助 assets: 在项目编译的过程中会被webpack处理解析为模块依赖,只支持相对路径的形式,如< img src=”./logo.png”>和background:url(./logo.png),”./logo.png”是相对资源路径,将有webpack解析为模块依赖 static: 在这个目录下文件不会被webpack处理,简单就是说存放第三方文件的地方,不会被webpack解析。他会直接被复制到最终的打包目录(默认是dist/static)下。必须使用绝对路径引用这些文件,这是通过config.js文件中的build.assetsPublic和build.assertsSubDirectory链接来确定的。任何放在static/中文件需要以绝对路径的形式引用:/static[filename] 根据webpack的特性,总的来说就是static放不会变动的,第三档的文件,asserts放可能会变动的文件 问题代码: <img :ref="item.name" :src="img.imgtwoway" alt /> 组件data中 img.imgtwoway:'@/assets/images/xxx.png' 这样图片是加载不出来的,这样的情况下

jquery solutions to post to another site from static html page

ぃ、小莉子 提交于 2020-01-13 11:05:30
问题 Need to post data from a static html page to another page which is hosted on another domain. Normally I'd create and iframe with a form inside of it with a post method, and whose actions is directed to that web page, and finally submit that form. The complexity is I'd collect data from my static html page and create a similar (replica) form inside the iframe (with the above attributes viz method & action mainly); if there are a lot of fields I'd struggle to do it via javascript alone. So are

Best practice for updating/writing to static variable?

回眸只為那壹抹淺笑 提交于 2020-01-13 10:45:09
问题 I have a project which displays department documentation. I store all the docs (get from database) in a static arrayList. Every X hour, I have that arrayList rebuilt based on the new doc (if any) from the database. There is also a static variable to control to rebuild that array or not, set and unset in a method which does the rebuild task. Each web browser hit the server will create this class's instance, but the doc arrayList and that control variable is shared among all the class instances